我正在创建一个用于玩字谜的单词生成器,它适用于大约六个单词,然后显示“列表索引超出范围”。
这是我的代码:
def selection(word):
while True:
from random import randint
sel = randint(1,10)
print(word[sel])
input("\nPress enter to select a new word.")
print("Type in ten words to add to the list.")
words = []
words.append(input("1st word: "))
words.append(input("2nd word: "))
words.append(input("3rd word: "))
words.append(input("4th word: "))
words.append(input("5th word: "))
words.append(input("6th word: "))
words.append(input("7th word: "))
words.append(input("8th word: "))
words.append(input("9th word: "))
words.append(input("10th word: "))
input("\nPress enter to randomly select a word.")
selection(words)