import random times = 3 secret = random.randint(1,10) guess = 0 print("猜猜数字:") while (guess != secret) and (times > 0): temp = input() while not temp.isdigit(): temp = input("请重新输入一个整数:") guess = int(temp) times = times - 1 # 每输入一次,可用机会就-1 if guess == secret: print("奖励!") else: if guess > secret: print("大了大了~~~") else: print("小了,小了~~~") if times > 0: print("再试一次吧:") else: print("机会用光") print("游戏结束,Game over!")