Learning-Python-Team / word-game-tool

Basic tool to help players of word games, based around Scrabble, find the score of their words and assist them selecting the optimal word
MIT License
7 stars 8 forks source link

Program exit errors in lower case #8

Closed JiggsUK closed 5 years ago

JiggsUK commented 5 years ago

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?

shyamcody commented 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.

saiyencoder commented 5 years ago

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

JiggsUK commented 5 years ago

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

saiyencoder commented 5 years ago

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.

shyamcody commented 5 years ago

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().

JiggsUK commented 5 years ago

I've created a new branch exit-program-issue, please checkout to this branch and push any changes to there.

JiggsUK commented 5 years ago

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?

saiyencoder commented 5 years ago

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

JiggsUK commented 5 years ago

Sounds good mate!

JiggsUK commented 5 years ago

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

Levi-Lesches commented 5 years ago

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

vahidanwari commented 5 years ago

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?

Levi-Lesches commented 5 years ago

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.

saiyencoder commented 5 years ago

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.

JiggsUK commented 5 years ago

@Levi-Lesches I like your thinking. What if we were to bundle it up as an executable program, would Ctrl-C still work?

Levi-Lesches commented 5 years ago

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()
JiggsUK commented 5 years ago

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!

Levi-Lesches commented 5 years ago

"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