Python纯菜鸟,猜数游戏程序遇上一个问题求帮助
importrandomsecret=random.randint(1,100)guess=0tries=0print("AHOY!IamtheDreadPirateRo...
import random
secret = random.randint(1,100)
guess = 0
tries = 0
print("AHOY! I am the Dread Pirate Roberts, and I have a secret!")
print("It is a number from 1 to 99. I will give you 6 tires.")
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 guess! Better luck next time, matey!")
print("The secret number was 49"), secret
每次运行为什么总是说
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\My new.py", line 12, in <module>
if guess < secret:
TypeError: unorderable types: str() < int()
到底是哪里出了问题 ,菜鸟求解啊 展开
secret = random.randint(1,100)
guess = 0
tries = 0
print("AHOY! I am the Dread Pirate Roberts, and I have a secret!")
print("It is a number from 1 to 99. I will give you 6 tires.")
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 guess! Better luck next time, matey!")
print("The secret number was 49"), secret
每次运行为什么总是说
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\My new.py", line 12, in <module>
if guess < secret:
TypeError: unorderable types: str() < int()
到底是哪里出了问题 ,菜鸟求解啊 展开
展开全部
我在 python2.7版本运行无任何问题
我估计你是其他的版本python ,解释器把你获得的输入变成 str 了,
可以type(guess) 看看是什么类型
你的问题出现在 if guess < secret:
你可以 把
while guess != secret and tries < 6:
guess = input("What is yer guess?")
#增加两句话
print type(guess)
guess = int(guess)
#
if guess < secret:
print("Too low, ye scurvy dog!")
elif guess > secret:
print ("Too high, landlubber!")
我估计你是其他的版本python ,解释器把你获得的输入变成 str 了,
可以type(guess) 看看是什么类型
你的问题出现在 if guess < secret:
你可以 把
while guess != secret and tries < 6:
guess = input("What is yer guess?")
#增加两句话
print type(guess)
guess = int(guess)
#
if guess < secret:
print("Too low, ye scurvy dog!")
elif guess > secret:
print ("Too high, landlubber!")
追问
我本来用的3.3,现在换了2.7可以了。
可是为什么得数会出现这样
What is yer guess?5
Too low, ye scurvy dog!
No more guess! Better luck next time, matey!
The secret number was 49 50
What is yer guess?
2013-06-06 · 知道合伙人互联网行家
关注
展开全部
你的代码在我这里没问题。。。我用Python 2.7.3
这个问题是在输入猜测的数以后出的呢,还是以前?
这个问题是在输入猜测的数以后出的呢,还是以前?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这程序好搞笑呀·· Think in Java 那本书里面也有个类似的·····
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\My new.py", line 12, in <module>
if guess < secret:
TypeError: unorderable types: str() < int()
两个数据类型不匹配
if int(guess) < secret 即可
File "C:\Users\Administrator\Desktop\My new.py", line 12, in <module>
if guess < secret:
TypeError: unorderable types: str() < int()
两个数据类型不匹配
if int(guess) < secret 即可
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |