import random

def guess_word(word): chances = 3 while chances > 0: guess = input("请猜一个单词: ") if guess == word: print("猜对了!") return else: chances -= 1 if chances > 0: print("猜错了,请再接再厉!还剩{}次机会。".format(chances)) print("很遗憾,没有猜中。正确的单词是{}。".format(word))

while True: words = ["apple", "banana", "orange", "grape", "watermelon"] word = random.choice(words) guess_word(word) choice = input("是否继续?(y/n)") if choice.lower() != "y": brea

用Python3写一段猜字谜的代码每段字谜有三次机会回答若回答正确显示猜对了!若回答错误显示猜错了请再接再厉!并且显示还剩多少次机会。每玩完一轮后询问玩家是否继续。

原文地址: https://www.cveoy.top/t/topic/huKd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录