0
Help, input does not work
hello everyone Iâm trying to run this python code, Iâm a beginner and itâs a very simple code but it does not work it gives an error can someone help me solve this thank you so much age = input(âhow old are you?â) if age > 10: print(âyou are oldâ) else: print(âyou are youngâ)
8 RĂ©ponses
+ 3
Alex
You have to use int() because your input is string and you have to convert it to integer. Why? Because in the line :
if age > 10
you are comparing two numbers. You can't compare string and number.
With integers you can do math, with string not exactly.
Try these examples to see the difference between string and integer:
print("2+2")
print(2+2)
+ 6
There are two things.
First, you need to convert your string input to integer.
Second, in Python, indentations are important, add them after if condition and else. Here:
age = int(input("how old are you?"))
if age > 10:
print("you are old")
else:
print("you are young")
+ 1
thank u voja !
+ 1
thank you voja ! you are the best ;)
0
Can you say what the error is?
0
He already explained your error
It's there age= ERROR(input(....
0
can you explain why i need to use int ? int()
0
Second line of voja