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.这是一个1-99的一个数字,您有六次机会!")
while guess != secret and tries < 6:
guess = int(input("What's yer guess?请输入你的数字"))#input要转换成int 书中没有注明,所以调试时出错。
print(guess,secret,tries) #这行是我加入,想知道当前三个的数值是多少。
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 sectet number was秘密数字是",secret)