菜鸟关于Python的问题,求解答

一个很简单的猜数游戏importrandomsecret=random.randint(1,100)guess=0tries=0print"AHOY!IamtheDrea... 一个很简单的猜数游戏
import random

secret = random.randint(1,100)
guess = 0
tries = 0

print "AHOY! I am the Dread Prirate Roberts, and I have a secret!"
print "It is a number from 1 yo 99. I will give you 6 tries. "

while guess != secret and tries < 6:
guess = input("what is yer guess? ")
if guess < secret:
print "Too low, ye scurvy dog!"
elif guess > secret:
print "Too high, landlubber!"
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
为什么每次运行结果都是
AHOY! I am the Dread Prirate Roberts, and I have a secret!
It is a number from 1 yo 99. I will give you 6 tries.
what is yer guess? 1
Too low, ye scurvy dog!
No more guesses! Better luck next time, matey!
The secret number was 47
what is yer guess? 2
Too low, ye scurvy dog!
No more guesses! Better luck next time, matey!
The secret number was 47
what is yer guess? 3
Too low, ye scurvy dog!
No more guesses! Better luck next time, matey!
The secret number was 47
what is yer guess? 47
Avast! Ye got it! Found my secret, ye did!
我用的版本是2.7.5
展开
 我来答
bdwisyou7d
2013-06-18 · TA获得超过1.3万个赞
知道大有可为答主
回答量:3774
采纳率:81%
帮助的人:1085万
展开全部
你将
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
改成
if guess == secret:
print "Avast! Ye got it! Found my secret, ye did!"
elif tries >= 6:
print "No more guesses! Better luck next time, matey!"
print "The secret number was", secret
穷图末录
2013-06-18 · TA获得超过457个赞
知道小有建树答主
回答量:337
采纳率:100%
帮助的人:155万
展开全部
检查一下最后两个print前面的空格吧,估计是有个是Tab,有个是空格
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
Jakey2333
2013-06-18 · TA获得超过268个赞
知道小有建树答主
回答量:253
采纳率:100%
帮助的人:175万
展开全部
- -你想问什么?是要每行注释?程序目测貌似没问题啊.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式