+ 1

TypeError: unorderable types: str() > int() please help in explaining this error

#Why is this code wrong? num = input ('enter number') if num > 5: print("Bigger than 5") if num <=47: print("Between 5 and 47")

2nd Apr 2018, 4:00 PM
R Sha
3 Antworten
+ 2
You must convert the input from a string to an integer. You can't compare a string with an int :)
2nd Apr 2018, 4:04 PM
Justin Hinkle
Justin Hinkle - avatar
+ 1
Try this: num = int(input("enter number")) # You have to convert input() to int as it returns a string by default
2nd Apr 2018, 4:04 PM
777
777 - avatar
0
thanks a lot. so it takes input in form of string and i should convert it to integer using function int. got it. :) cheers!
2nd Apr 2018, 4:05 PM
R Sha