python # 定义一些动物 animals = ["猫", "狗", "兔子", "猴子", "狮子 # 随机选择一个动物 chosen_animal = random.choice(animals) # 记录猜测的次数 attempts = 0 while True: guess = input("猜一个动物: ").lower() attempts += 1 if guess == chosen_animal: print(f"恭喜你猜对了!你用了 {attempts} 次尝试。动物是 {chosen_animal}") break else: print("猜错了,再试试。") play_again = input("是否继续游戏?(y/n): ").lower() if play_again == "y": continue else: print("游戏结束。")
|