Skip to content

Instantly share code, notes, and snippets.

@IdlePhysicist
Created July 22, 2019 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IdlePhysicist/f6a8929b34d93d0938189c4882210b83 to your computer and use it in GitHub Desktop.
Save IdlePhysicist/f6a8929b34d93d0938189c4882210b83 to your computer and use it in GitHub Desktop.
Simple user prompt function
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