+ 2
how do I compare a variable with a number?
I've started to learn python just now,and I'm trying to get 2 numbers from a user and compare it with 10 something like this : x = input('please enter an integer') y = input('please enter an integer') z = 10 if x+y < z : print('the result of your entered numbers are below 10') else: if x+y > z : print('the result of your entered numbers are over 10') else: print('the number is invalid') but when I used this code I get the error : '<' not supported between instances of 'str' and 'int'
6 Answers
+ 7
This is telling you that one or more of your variables is actually a string datatype rather than an integer, and you can't do comparisons between strings and ints. wrap int() around the input like
int(input('thing'))
a similar thing will apply when concatenating strings together, if you use an int it won't work, so you must use str() to convert the result first. Be aware of the data types you are handling! :)
+ 5
x =int( input('please enter an integer'))
y =int( input('please enter an integer'))
z = 10
The function input returns a string. If you convert it to integer, it should work.
+ 2
Mr.Zre
https://code.sololearn.com/cwRbUbK3lOgW/?ref=app. try this code on your
0
can you help me?
0
Dr.Mahdi help? yes
0
can i have a better way to communicate with you. It's hard to say