+ 1

How do I put someone's input into a variable and gather info about the input and use it in an if statement?

25th Mar 2017, 10:56 PM
privrax.
privrax. - avatar
3 odpowiedzi
+ 3
Here's getting the answer to a simple yes/no question answer = raw_input("Are you sure? > ") if answer == "yes": do_the_one_thing() else; do_the_other_thing() Here's picking something from a list print("1. First option") print("2. Second option") print("3. Third option") print("4. Last option") choice = raw_input("Please choose an option > ") if choice == "1": handle_first_option() elif choice == "2": handle_second_option() elif choice == "3": handle_third_option() elif choice == "4": handle_last_option() else: print("Unrecognized option. Please try again")
25th Mar 2017, 11:40 PM
tom barron
+ 1
Okay thanks!
25th Mar 2017, 11:42 PM
privrax.
privrax. - avatar
+ 1
remember the part where the if statements have " " as an argument. if you take input as a string(default) then you must check it as a string. chance=input("Pick a number") if chance == "1": True if chance == 1: False You can get the input as an integer however. chance=int(input("Pick a number")) if chance == "1": False if chance == 1: True
26th Mar 2017, 12:18 AM
LordHill
LordHill - avatar