Skip to content

Instantly share code, notes, and snippets.

@wkettler
Last active August 29, 2015 13:56
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 wkettler/9235529 to your computer and use it in GitHub Desktop.
Save wkettler/9235529 to your computer and use it in GitHub Desktop.
def prompt_yn(question):
"""
Prompt the user with a yes or no question.
Input:
question (str): Question string
Output:
answer (bool): Answer True/False
"""
while True:
choice = raw_input("%s [y|n] " % question)
if choice == "y":
answer = True
break
elif choice == "n":
answer = False
break
else:
print "Invalid input."
return answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment