我试图创建一个猜数游戏,但我收到“guesstaken”的错误我从http://inventwithpython.com/IYOCGwP_book1.pdf第 57 页复制了代码。对不起,我对 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")