| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

已结贴   问题点数：20  回复次数：4

import random
secret = random.randint(1,99)
guess = 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 your 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 questions! Better luck next time, matey!")
print ("The secret number was, secret")

Traceback (most recent call last):
File "D:/Python/Python Practice/Number-guessing Game.py", line 9, in <module>
if guess < secret:
TypeError: '<' not supported between instances of 'str' and 'int'

得分:10

import random
secret = random.randint(1,99)
guess = 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 your 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 questions! Better luck next time, matey!")
print ("The secret number was, secret")

Traceback (most recent call last):
File "D:/Python/Python Practice/Number-guessing Game.py", line 9, in <module>
if guess < secret:
TypeError: '<' not supported between instances of 'str' and 'int'

得分:0

得分:10

`guess = int(input ("what's your guess?"))`
得分:0

• 5
• 1/1页
• 1