这是我的代码:
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 tries < 6 and guess != secret:
guess = input ("What's 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 it!"
else:
print ("No more guesses! Better luck next time, matey!)
print ("The secret number was"), secret
出于某种原因,我在“while”上得到了无效的语法。我似乎无法找出原因,因为它出于某种原因使用过。