Why Is My If Age Syntax Not Working? (beginner Python)
Well, it's my first day using python 3 and I have come across a problem. My script is supposed to say you're old enough to play if the age entered is over 13, but it says you're ol
Solution 1:
You are comparing a string to an integer:
age = int(input())
if age >= "13":
In Python 2, a string is always larger than a number. Use numbers instead:
ifage>=13:
In Python 3, comparing strings with integers like that raises an error instead:
>>>13>= "13"
Traceback (most recent calllast):
File "<stdin>", line 1, in<module>
TypeError: unorderable types: int() >= str()
giving you a clearer message about what you are doing wrong.
Post a Comment for "Why Is My If Age Syntax Not Working? (beginner Python)"