Skip to content Skip to sidebar Skip to footer

Type Error >= Not Supported Between Instances Of 'str' And 'int'

I have already written out my code but I keep getting an error message on if personsAge >= 1. Here is the error: type error >= not supported between instances of 'str' and '

Solution 1:

You are converting your input into a string instead of an integer.

Use int() to convert your input to an integer:

personsAge = int(input("<Enter your age>"));

Then you will be able to compare it to other integers.

Don’t forget to convert your personsAge integer to a string with str() everytime you concatenate personsAge with a string. Example:

print("My age is " + str(personsAge));

It is good practice to add error-handling where user input is not guaranteed to be of the required type. For example:

whileTrue:
    try:
        personsAge = int(input("<Enter your age>"))
        breakexcept ValueError:
        print('Please input an integer.')
        continue

Post a Comment for "Type Error >= Not Supported Between Instances Of 'str' And 'int'"