Monday, 9 September 2013

how do I fix this error in python 3.3? TypeError: unorderable types: str() < int()

how do I fix this error in python 3.3? TypeError: unorderable types: str()
< int()

i was trying to create a number guessing game but I get the error for
"guessestaken"I copied the code from
http://inventwithpython.com/IYOCGwP_book1.pdf page 57.Sorry I am a bit new
to python.
import random
guessestaken=0
print ("hello what ur name?")
myname=input()
number=random.randint(1,20)
print ("well " + myname + " i am thinking of a number guess it")
while guessestaken < 6 :
guessestaken=guessestaken+1
guess =input('take a guess')
guess = int(guess)
if guess <number:
print('too low')
if guess >number:
print ('too high')
if guess ==number:
break
if guess ==number:
guessestaken=str(guessestaken)
print ('good job ' + myname + ' you are right!')
print ('you guessed it in ' + guessestaken + ' guesses')
if guess !=number:
guessestaken = str(guessestaken)
print ("I am sorry but you couldn't get it right")
print ("you couldn't guess it in " + guessestaken + " guesses")

No comments:

Post a Comment