afeefkhateeb afeefkhateeb - 1 year ago 72
Python Question

Error when Executing a python code

I am new to Python programming. I am writing the code below, and when I execute it the IDE returns an error message : TypeError: unorderable types: str() < int()

Code below :

print("What is your name?")

name = input()

print("What is your age?")

age = input()

if name=='Jack':

print ("Hello Jack")

elif age<12:

print("You are not Jack")

The error

elif age<12:
TypeError: unorderable types: str() < int()

Answer Source

input() returns a string. You cannot directly compare a string to an integer.

Convert age to an integer by calling int():

age = int(input())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download