我现在正在构建一个简单的刽子手游戏,我希望能够识别用户在列表中猜测特定字母的位置例如,如果单词列表是[D,R,A,G,O,N]——而用户猜测是A,那么我希望能够得到一个返回值,即4……这是我迄今为止失败的代码
import random
word_list = ['red', 'better', 'white', 'orange', 'time']
hidden_list = []
selected_word = random.choice(word_list)
letters = len(selected_word)
selected_word_list = list(selected_word)
game_playing = True
print('My word has ' + str(letters) + ' letter(s).')
print(selected_word_list)
for i in selected_word_list:
hidden_list.append('_')
while game_playing:
print(hidden_list)
guess = input('What letter do you want to guess?')
if guess in selected_word_list:
print('Nice guess!')
else:
print('Nope!')