0

help me with my python code :(

I am trying to write a short program that has the user enter there age and it will let them know if they are an adult or a kid. Here is the code : adult = 18 kid = 17 answer = "" status = "" input (answer) if (answer <=(adult)): (status) = ("you are an adult") print (status) if(answer >=(kid)): (status) = ("you are a kid") print (status) What did work was this : adult = 18 kid = 17 answer = 23 status = "" if (answer >=(adult)): (status) = ("you are an adult") print (status) if (answer <=(kid)): (status) = ("you are a kid") print (status) So how do i get input from the user? i know its input but make it so when someone set an input that it becomes equal to answer

10th Dec 2016, 4:37 AM
Ezekiel Rivera
Ezekiel Rivera - avatar
3 Answers
+ 1
This should do it: adult = 18 answer = int(input()) if answer >= adult: status = "you are an adult" else: status = "you are a kid" print (status)
10th Dec 2016, 5:05 AM
Severiano Jaramillo Quintanar
Severiano Jaramillo Quintanar - avatar
0
This will work if you use Python3, if you use Python2 change answer = int(input()) to answer = int(raw_input())
10th Dec 2016, 5:07 AM
Severiano Jaramillo Quintanar
Severiano Jaramillo Quintanar - avatar
0
You were trying to compare a string with a integer in line 7. And you tried to store the user input in the variable 'answer', but you assigned a string type to the answer variable (answer = "") in line 3. Here is a sample code that I did for you. https://code.sololearn.com/csux2GODzl0b Check and send any doubt.
10th Dec 2016, 5:16 AM
Rodrigo Monney
Rodrigo Monney - avatar