-2

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()
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Alex Apostolu
  • 19
  • 1
  • 5
  • Out of curiosity, is there an upper limit on the number that you're allowed to pick? There's a simple way to cut down on the number of guesses needed if the range isn't infinite. – Carcigenicate Sep 07 '17 at 22:33

1 Answers1

0

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:"))
George
  • 66
  • 1
  • 1
  • 10