|

楼主 |
发表于 2023-5-3 16:06:04
|
显示全部楼层
重发
- import random
- difficulty = int(input('选择难度(输入1、2或3)\n 1 简单\n 2 正常\n 3 困难\n'))
- if difficulty == 1:
- lives = 12
- elif difficulty == 2:
- lives = 9
- else:
- lives = 6
- #可自行修改列表“words”的单词
- words = ['impossible', 'hopeless', 'quickly', 'democracy', 'science', 'geography', 'establishmentarian', 'electrocardiogram', 'congratulations', 'revolutionization']
- secret_word = random.choice(words)
- clue = []
- i = 0
- while i < len(secret_word):
- clue.append('?')
- i += 1
- guessed_word_correctly = False
- unknown_letters = len(secret_word)
- def update_clue(guessed_letter, secret_word, clue, unknown_letters):
- j = 0
- while j < len(secret_word):
- if guessed_letter == secret_word[j]:
- clue[j] = guessed_letter
- unknown_letters -= 1
- j += 1
-
- return unknown_letters
- while lives > 0:
- print(clue)
- print('剩余生命值:' + str(lives))
- guess = input('猜单词中的一个字母或者整个单词:')
- if guess == secret_word:
- guessed_word_correctly = True
- break
-
- if guess in secret_word:
- unknown_letters = update_clue(guess, secret_word, clue, unknown_letters)
- else:
- print('错误!你失去了一条生命。')
- lives -= 1
-
- if unknown_letters == 0:
- guessed_word_correctly = True
- break
- if guessed_word_correctly:
- print('你赢了!这个单词是' + secret_word)
- else:
- print('你输了!这个单词是' + secret_word)
复制代码 |
|