私はPythonで辞書を試してきたので、参照されていると思うので「マジックナンバー」を削除できますが、エラーが発生し続けます:タイプ「NoneType」のオブジェクトにはlen()がありません。私の絞首刑執行人プログラムで時々発生するだけで、その理由はわかりません。これは、クラッシュすると思われる一般的な領域です。
animals = 'ape bear beaver cat donkey fox goat llama monkey python bunny tiger wolf'.split()
colors = 'yellow red blue green orange purple pink brown black white gold'.split()
adjectives = 'happy sad lonely cold hot ugly pretty thin fat big small tall short'.split()
names = {'animals': animals, 'colors': colors, 'adjectives': adjectives}
categories = [names['animals'],names['colors'],names['adjectives']]
def getRandomWord(wordList):
wordList = random.choice(list(names.keys()))
wordIndex = random.randint(0,len(wordList))
print(animals[wordIndex])
if(random.choice(list(names.keys())) == 'animals'):
print("The category is animals!")
return animals[wordIndex]
if(random.choice(list(names.keys())) == 'colors'):
print("The category is colors!")
return colors[wordIndex]
if(random.choice(list(names.keys())) == 'adjectives'):
print("The category is adjectives!")
return adjectives[wordIndex]
問題を解決するにはどうすればよいですか?