Last active
November 18, 2024 11:01
-
-
Save garrettdreyfus/8153571 to your computer and use it in GitHub Desktop.
Dead simple python function for getting a yes or no answer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def yes_or_no(question): | |
reply = str(raw_input(question+' (y/n): ')).lower().strip() | |
if reply[0] == 'y': | |
return True | |
if reply[0] == 'n': | |
return False | |
else: | |
return yes_or_no("Uhhhh... please enter ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I prefer this approach:
The reason why is because I split whether I'll re-ask the question into another point whereas the value sanitization and checking is performed upon the function itself. Furthermore I set the default value as well. Furthermore I map any Greek Input given from user intop its respective English one in case keyboard layout is a non-English one.