0
TypeError: '>' not supported between instances of 'str' and 'int'
Why can't i use this code. How can fix this to still have my program do what i want it to do. x = input ("please enter your name:") y = 15 print ("hey " + x) z = input ("please enter age:") p = z if p > y: print('Hey ' + x + 'You are older than me') else: print('HaHa Im older than you!')
2 ответов
+ 14
# convert your input z to integer #
# z = (int(input("please enter age.")))
x = input ("please enter your name:")
y = 15
print ("hey " + x)
z = (int(input("please enter age:")))#explicitly convert input to number works fine
p = z
if p > y:
print('Hey ' + x + ' You are older than me')
else:
print('HaHa Im older than you!')
0
Need to type the whole traceback error. It pointed to the following code:
p > y
Hence the change would be in that line or before it where “p = z”.
I agree with Lord about type conversion, but not the location.
I would change the following code:
p=z
To:
p=int(z)