import random

def guess_game(): word_list = ['apple', 'banana', 'orange', 'grape', 'watermelon'] word = random.choice(word_list) chances = 3 while chances > 0: guess = input("Guess the word: ") if guess == word: print("You guessed it right!") return else: chances -= 1 if chances == 0: print("Sorry, you ran out of chances!") else: print("Sorry, wrong guess. Please try again. You have", chances, "chances left.")

while True: guess_game() choice = input("Do you want to play again? (yes or no)") if choice.lower() != "yes": brea

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

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

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