新手之路:代码定义错误

代码如下:

import random
secret = random.randint(1,99)
gurss = 0
tries = 0
print "AHOY! I'm the Dread Pirate Roberts, and I have a secret!"
print "It is a number from 1 to 99. I'll give you 6 tries."
while guess != secret and tries < 6:
    guess = input ("What's yer guess?")
    if guess < secret:
        print "Two low,ye scurvy dog!"
    elif guess > secret:
        print "Two high,landubber!"


    tries = tries + 1


if guess == secret:
    print "Avast! Ye got it! Found my secret, ye did!"
else:
    print "No more guesses! Better luck next time,matey!"
    print "The secret number was", secret

运行错误提示:

Traceback (most recent call last):
  File "C:/Users/whisk/Desktop/编程学习/list.1-2.py", line 7, in <module>
    while guess != secret and tries < 6:
NameError: name 'guess' is not defined

是根据书籍《父与子的编程之旅》学习的,刚开始,对照了书上和自己写的代码,并没有拼写错误,希望有大神点一下,谢谢。


阿晨1998
浏览 381回答 2
2回答

SMILET

gurss = 0guess拼写错误。。。。

慕娘9325324

第三行 guess
打开App,查看更多内容
随时随地看视频慕课网APP