What is an unorderable type?

Question:

This is different from other projects because it is simpler and the goal is to see how fast the computer can guess your number.

There is something wrong with the code below:

number = input("Please enter a number:")
guess = 0

while guess < number:
    guess += 1
    print (guess)

When I input let’s say 5, then I get the following message:

Traceback (most recent call last):
  File "..Playground", line 4, in <module>
    while guess < number:
TypeError: unorderable types: int() < str()
Asked By: Alex Apostolu

||

Answers:

The value that you are getting from the input() function is not a number but a unicode string that can contain numbers,symbols and letters.

So when the flow executation goes to the if statement you are comparing a string(which could be “5” but also “Hello…”) to a number, something that is invalid.

Simply convert the variable number to int. This could help:

number = int(input("Please enter a number:"))
Answered By: George
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.