Skip to content

Instantly share code, notes, and snippets.

@jorge-lavin
Created January 30, 2015 12:09
Show Gist options
  • Save jorge-lavin/959f67026eb6907720b9 to your computer and use it in GitHub Desktop.
Save jorge-lavin/959f67026eb6907720b9 to your computer and use it in GitHub Desktop.
Ask user and return boolean.
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