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
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)
0
This will work if you use Python3, if you use Python2 change
answer = int(input())
to
answer = int(raw_input())
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.