Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Slightly advanced version of this.
- # It works if the person enters Y, YES, Yes, yES, and so on for
- # Yes, No, True, and False.
- # The key to this is on two parts.
- # 1) There is the dictionary names switch. This is so named
- # because I am using it like it is a switch statement in
- # other languages.
- # 2) The switch.get(user_input.lower()) part is the other key.
- # It takes what the user put in and converts it to lower
- # case, then tests it against the dictionary. If there is
- # a match, it returns True or False as a boolian. Otherwise
- # it returns the special type of None and the while loop
- # continues.
- ## Test run results:
- ##
- ##>>>
- ##Is Lelis Online ? Answer True or False : g
- ##Just answer 'True' or 'False'
- ##
- ##Is Lelis Online ? Answer True or False : t
- ##Hi! Desculpa o atraso; ainda podemos fazer algo?
- ##>>> ===================================== RESTART =====================================
- ##>>>
- ##Is Lelis Online ? Answer True or False : FaLsE
- ##Sorry! I totally forget you. Muito contente por encontrar um crioulo. Keep in touch.
- ##>>>
- user_input=None
- switch = {'true':True,'t':True,'yes':True,'y':True,'false':False,'f':False,'no':False,'n':False}
- while user_input==None:
- user_input=raw_input("Is Lelis Online ? Answer True or False : ")
- user_input=switch.get(user_input.lower())
- if user_input==None:
- print "Just answer 'True' or 'False'\n"
- if user_input == True:
- print "Hi! Desculpa o atraso; ainda podemos fazer algo?"
- else:
- print "Sorry! I totally forget you. Muito contente por encontrar um crioulo. Keep in touch."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement