import random def guess_number_game(): number = random.randint(1, 100) chances = 10 print("欢迎来到猜数字游戏!") print("我已经生成了一个 1 到 100 之间的整数。你有 10 次机会猜对它。") while chances > 0: guess = int(input("请输入你猜测的数字:")) if guess < number: print("猜小了!") elif guess > number: print("猜大了!") else: print("猜对了!") return chances -= 1 print("剩余机会:", chances) print("游戏结束,没有猜到。正确答案是:", number) guess_number_game()