Advertisement
DeaD_EyE

yes / no

Jul 2nd, 2017
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. def get_answer(prompt):
  2.     retval = {'yes': True, 'no': False}
  3.     while True:
  4.         answer = input(prompt).strip().lower()
  5.         # in operator looks up the keys in a dictionary
  6.         if answer in retval:
  7.             # returns the value of the key
  8.             return retval[answer]
  9.  
  10. print(get_answer('yes / no: '))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement