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 yer guess? ")
if guess < secret:
print ("Too low, ye scurvy dog")
elif guess > secret:
print ("Too high, landrubber!")
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)
我一直收到这个错误:如果猜测值小于秘密值: TypeError: 无法比较类型:str() < int()
print
,所以input()
不是问题。 - Justin Ardiniprint()
是完全有效的。无论如何,为了澄清已进行编辑。 - Chinmay Kanchiprint
可以使用与函数调用相同的语法,尽管我确实同意它通常不会以那种方式使用。 - Chinmay Kanchi