Created
January 30, 2015 12:09
-
-
Save jorge-lavin/959f67026eb6907720b9 to your computer and use it in GitHub Desktop.
Ask user and return boolean.
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
def ask_boolean(message): | |
""" | |
Asks a yes/no question to the user and looks if the answer is yes or no | |
@return answer: A boolean representing the user answer | |
""" | |
yes = ['YES', 'Yes', 'yes', 'y'] | |
no = ['NO', 'No', 'n'] | |
answer = raw_input(message+'{new_line}Choose one of [{yes}] or [{no}] {new_line}'.format(new_line=os.linesep, yes=' '.join(yes), no=' '.join(no))) | |
if answer in yes: | |
return True | |
elif answer in no: | |
return False | |
else: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment