Closed JiggsUK closed 5 years ago
I think we can create a custom regex and then check using that. I have sent it to nakulkd in slack, he will check and upload them.
Are we looking to remove the underscore from the input due to it being a special character?
If so, would it be easier to just change EXIT_TOOL
to just EXIT
or exit
?
We can just upper or lower the input once it passes the other validations
We could separate the exit question from the user entering a word - so after we return the score, ask if they want to exit with a Y or N. Then it's a simple: if Y, exit --- elif N continue.
That would eliminate any need for regex?
We would need to account for a user putting in junk here too, but if we know its only 2 options Y or N, then you can reject everything that isn't a Y or N
True but from a users perspective wouldn't it be annoying to get a question to exit the game after each score is displayed?
I agree that the Y and N option would be easier to implement than regex but as a user reading this, this would get annoying.
I have created a new pull request with two files, named checkstringer.py and scrabble_main.py. checkstringer.py is a new file with a function with a custom regex. and also scrabble_main is a updated version to main, which just updates the input into upper().
I've created a new branch exit-program-issue, please checkout to this branch and push any changes to there.
True but from a users perspective wouldn't it be annoying to get a question to exit the game after each score is displayed?
I agree it would be annoying, it would need to be something more than exit though as what of that is the word they are checking the score of?
True but from a users perspective wouldn't it be annoying to get a question to exit the game after each score is displayed?
I agree it would be annoying, it would need to be something more than exit though as what of that is the word they are checking the score of?
Got me there! I remember creating a small script and using 'Q' as the exit input option. Since scrabble is a 2+ word input using (Q)uit should work. Then we can just add a verification if they really want to quit the program with the Y and N option, just incase they accidentally hit Q
Sounds good mate!
Or you can leave it as EXIT_TOOL and move the .upper()
out of the word_to_score.py
and add it to the end of the input line?
user_input = input('Enter the word you want to score: ').upper()
means it will pass the exit_tool scenario as it immediately becomes EXIT_TOOL
How about Ctrl-C (or CMD-C)? Python already handles this, we can also put up a prompt.
Something simple like: Press Ctrl-C to exit anytime
another option could be that we don't ask the user to continue (Y/N), but instead it goes back to default "Enter a word to calculate score or press 9( or some combination of digits e.g. 999) to exit"? Is it possible to use the Esc key to exit?
Well, we could possibly rig something up to Esc, but that will take a while and a big import. Shouldn't we just use Ctrl-C? Again, it's built in to Python, and will exit any script.
I uploaded some code that handles the exit protocol. Feel free to take a look at exit_program.py
and the main file to see how it is implemented. I welcome any feedback on how to improve it.
@Levi-Lesches I like your thinking. What if we were to bundle it up as an executable program, would Ctrl-C still work?
Yep!
And, we can also add our own logic to catch Ctrl-C presses, like this:
try:
our()
program()
except KeyboardInterrupt:
respnse = input("Are you sure you want to quit?")
if response == "yes": quit()
I think the 'enter Q to exit' is cleaner for now, but I'm adding your idea to my future project developments as dealing with interrupts/exceptions is a good thing to know. With the exit-program branch now merged with phase-1-dev, I am closing this issue as you have completed the issue at hand - well done guys, good job!
"Q" as an exit key is fine, just as a reminder, you can't get rid of Ctrl-C
-- it can still be used to quit. The only way to prevent Ctrl-C
(or do some cleanup work if Ctrl-C
is pressed) would be to use a try
statement like above
When you run the program, try entering theses words:
exit_tool
What happens? What could we do to fix this? Is linking the entered word to an exit command the optimal way to exit?