'When I run my code, I get an error which states TypeError: '<' not supported between instances of 'int' and 'str'
This is my code. I can input, but when I press enter, I get the error.
import math
x = 13
age = input("Please input your age.")
if x < age:
print("Nice, you can use this website!")
if x > age:
print("Sorry, you are too young")
if x == age:
print("Nice, you can use this website!")
Solution 1:[1]
input returns a str, not an int.
...
age = int(input("Please input your age"))
...
Also, consider consolidating your if statements like so:
if x <= age:
print("Nice, you can use this website!")
else:
print("Sorry, you are too young")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Josh Clark |
