为了账号安全,请及时绑定邮箱和手机立即绑定

新手之路:代码定义错误

新手之路:代码定义错误

阿晨1998 2018-07-16 11:20:21
代码如下:import randomsecret = random.randint(1,99)gurss = 0tries = 0print "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 + 1if 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是根据书籍《父与子的编程之旅》学习的,刚开始,对照了书上和自己写的代码,并没有拼写错误,希望有大神点一下,谢谢。
查看完整描述

2 回答

?
SMILET

TA贡献1796条经验 获得超4个赞

gurss = 0

guess

拼写错误。。。。


查看完整回答
反对 回复 2018-07-17
?
慕娘9325324

TA贡献1783条经验 获得超5个赞

第三行 guess

查看完整回答
反对 回复 2018-07-17
  • 2 回答
  • 0 关注
  • 380 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号