猜动物游戏

[复制链接]
发表于 2024-6-23 15:49:10 | 显示全部楼层 |阅读模式
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("游戏结束。")

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表