【发布时间】:2020-03-25 05:17:52
【问题描述】:
import random
word_list = ['kill', 'happy']
choose = random.choice(word_list)
choose_list = list(choose)
players_list = ['_'] * len(choose)
while choose_list != players_list:
# inp is the input of the user
inp = input("Input:\n")
# index_inp is the position of the input
index_inp = choose_list.index(inp)
if inp in choose_list:
players_list[index_inp] = inp
print(players_list)
当单词是kill 并且我输入'l' 时,它只会在我的players_list 的一个位置插入字符,而不是两个位置。
【问题讨论】:
标签: python python-3.x list indexing