close

[Solved] TypeError: ‘<' not supported between instances of 'str' and 'int'

Hello Guys, How are you all? Hope You all Are Fine. Today I am just trying to make some automatic stuff But I am facing following error TypeError: ‘<‘ not supported between instances of ‘str’ and ‘int’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How TypeError: ‘<‘ not supported between instances of ‘str’ and ‘int’ Error Occurs ?

I am just trying to make some automatic stuff But I am facing following error.

TypeError: '<' not supported between instances of 'str' and 'int'

Here is my code.

usr_age = input("What is your Age? ")

if numerical_grade < 20:
    msg = "You are not allowed!!"
else:
    msg = "Go Ahead"

print(msg)

How To Solve TypeError: ‘<‘ not supported between instances of ‘str’ and ‘int’ Error ?

  1. How To Solve TypeError: '

    To Solve TypeError: '<' not supported between instances of 'str' and 'int' Error Here you are facing this error because in input you will recieve string and you are trying to compare string with int so just Change input string to an int object. Change this line usr_age = input(“What is your Age? “) With usr_age = int(input(“What is your Age? “))

  2. TypeError: '

    To Solve TypeError: '<' not supported between instances of 'str' and 'int' Error Here you are facing this error because in input you will recieve string and you are trying to compare string with int so just Change input string to an int object. Change this line usr_age = input(“What is your Age? “) With usr_age = int(input(“What is your Age? “))

Solution 1: Change input string to an int object

Here you are facing this error because in input you will recieve string and you are trying to compare string with int so just Change input string to an int object. Change this line

usr_age = input("What is your Age? ")

With

usr_age = int(input("What is your Age? "))

Solution 2: use try catch

You can use try catch if you want to convert string to int.

try:
  input_var = int(user_input)
except ValueError as err:
  pass 

Summary

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment