import random

def guess_word(): words = ['apple', 'banana', 'cherry', 'orange', 'pear'] word = random.choice(words) chances = 3 while chances > 0: print('Guess the word ({} chances left):'.format(chances)) guess = input().lower() if guess == word: print('You guessed it right!') return else: chances -= 1 print('Sorry, wrong guess. Please try again. {} chances left.'.format(chances)) print('Game over! The word was {}.'.format(word))

while True: guess_word() print('Do you want to play again? (y/n)') play_again = input().lower() if play_again != 'y': break print('Enter any number to quit:') quit_game = input() if quit_game.isdigit(): break

print('Thanks for playing!')

Python3 猜字谜游戏代码:三种机会,挑战你的词汇量!

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

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