Created
July 22, 2019 18:09
-
-
Save IdlePhysicist/f6a8929b34d93d0938189c4882210b83 to your computer and use it in GitHub Desktop.
Simple user prompt function
This file contains hidden or 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
CHOICE = {'yes': {'yes', 'y', ''}, 'no': {'no', 'n'}} | |
def YorN(text): | |
""" | |
This method prompts the user for an answer to a question. | |
`text` should be the prompt to that the user responds to. | |
""" | |
answer = input(f'{text} [Y/n] ').lower() | |
if answer in CHOICE['yes']: | |
return True | |
elif answer in CHOICE['no']: | |
return False | |
else: | |
return YorN(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment