LiamW
LiamW

Reputation: 21

New to Python - TypeError: '<' not supported between instances of 'str' and 'int'

I'm very new to programming and currently running through Al Sweigart's course on Udemy. I copied the code he was using for his elif example and I keep receiving the above error message - Can someone please explain why?..

Code and error below.

name = 'Bob'
age = '3000'
if name == 'Alice':
    print ('Hi Alice')
elif age < 12:
    print ('you are not Alice.')
elif age > 2000:
    print ('unlike you, ALice is no an undead, immortal vampire')
elif age > 100:
    print ('You are not Alice, Granny.')

Error:

Traceback (most recent call last):
  File "C:\Users\*****\AppData\Local\Programs\Python\Python38-32\elif_example.py", line 5, in <module>
    elif age < 12:
TypeError: '<' not supported between instances of 'str' and 'int'

Upvotes: 0

Views: 50

Answers (1)

ted
ted

Reputation: 14764

parse age to int: age = 3000 or age = int("3000")

Upvotes: 1

Related Questions