0

why does this not work

name = input("what is your name") age = input(" how old are you") if age == 13 and name == alex: print(" good for you") else: print(" oh hello" +name)

30th Jun 2016, 10:19 PM
Barry Yee
Barry Yee - avatar
3 Answers
0
alex is a string and must be quoted. I believe the interpreter has allocated a new variable alex which is uninitialized.
30th Jun 2016, 11:15 PM
Jeff
0
You need to quote the strings '13' and 'Alex'
30th Jun 2016, 11:19 PM
Leon
Leon - avatar
0
Looking at your code, it's comparing whatever the user has put as their name to a variable called alex which hasn't been declared. Also, when the user enters their age, this stores their input as a string so when comparing it will not match to the number 13. I've amended your code as follows: name = input("What is your name: ") print(name) age = int(input("How old are you: ")) print(age) if age == 13 and name == "alex": print("Good for you") else: print("Oh hello " +name) The int () before the input for the age variable will return a number to compare to 13. Hope this helps
2nd Jul 2016, 2:08 AM
Moosh
Moosh - avatar