[Tutor] Unorderable types

Cameron Simpson cs at cskk.id.au
Fri Aug 4 21:44:35 EDT 2017


[ Back onto the tutor list. - Cameron ]

On 04Aug2017 09:12, Howard Lawrence <1019shaun at gmail.com> wrote:
>This is the code from tutorial

Thank you.

>import random
>guessesTaken =0
>
>print ('hello what is your name')
>myName =input ()
>
>number = random.randint(1,20)
>print ('well, ' + myName + ', I am thinking of a number between 1 and 20')
>
>while guessesTaken < 6:
>    print ('take a guess')
>    guess=input ()
>    guess_value =int (guess)

Spooky :-) So you have "guess" containing the string from input(), and 
"guess_value" has the int.

>    guessesTaken = guessesTaken +1
>
>    If guess_value < number: # this is it
>        print('your guess is too low')

Strange, this should work. Btw, "If" should be lower case "if".

[...snip...]
># I changed all the "guess" to "guess_value" got the same result!
>
>This is it: traceback ( most recent call last):
>File "C:/User/Shaun/guessGame.py", line 19, in <module>
>If guess_value < number:
>typeError: unorderable types:int() < str ()

Interesting. Can you put this:

  print("type(guess_value) =", type(guess_value))
  print("type(number) =", type(number))

above that line and run it again? Because I just ran your code here and it 
worked for me.

>Hope this can help you and mostly me
>I don't wanna give up but help is scarce from my location

That's fine. The list is for help.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Tutor mailing list