Python 类型错误:';在<;字符串>';需要字符串作为左操作数,而不是列表

Python 类型错误:';在<;字符串>';需要字符串作为左操作数,而不是列表,python,python-3.x,Python,Python 3.x,我正在为我的GCSE计算项目创建一个刽子手游戏。我遇到了一个我似乎无法纠正的错误 以下是所有代码: import random #Creates a tuple with words in WORDS = ("church","smelly","chicks") #This picks a word randomly word = random.choice(WORDS) print("The word is", len(word), "letters long.") #This is

我正在为我的GCSE计算项目创建一个刽子手游戏。我遇到了一个我似乎无法纠正的错误

以下是所有代码:

import random

#Creates a tuple with words in
WORDS = ("church","smelly","chicks")


#This picks a word randomly
word = random.choice(WORDS)
print("The word is", len(word), "letters long.")


#This is the game
for i in range(1):
letter1 = input ("Guess a letter:")

if letter1 in word:
 print("Correct. This letter is in the word")
else:
 print("Incorrect. This letter is not in the word.")

for i in range(1):
letter2 = input ("Guess a letter:")

if letter2 in word:
 print("Correct. This letter is in the word")
else:
 print("Incorrect. This letter is not in the word.")

for i in range(1):
letter3 = input ("Guess a letter:")

if letter3 in word:
 print("Correct. This letter is in the word")
else:
 print("Incorrect. This letter is not in the word.")

for i in range(1):
 letter4 = input ("Guess a letter:")

if letter4 in word:
 print("Correct. This letter is in the word")
else:
 print("Incorrect. This letter is not in the word.")

for i in range(1):
letter5 = input ("Guess a letter:")

if letter5 in word:
 print("Correct. This letter is in the word")
else:
 print("Incorrect. This letter is not in the word.")

for i in range(1):
letter6 = input ("Guess a letter:")

if letter6 in word:
 print("Correct. This letter is in the word")
else:
 print("Incorrect. This letter is not in the word.")

all_letters = [letter1, letter2, letter3, letter4, letter5, letter6]

# Conditions for winning/losing
if all_letters in word:
 print("Well done, you got it.")
else:
 print("Sorry, You are the loser.")
当我运行程序时,我得到了这个错误

TypeError: 'in <string>' requires string as left operand, not list
TypeError:'in'需要字符串作为左操作数,而不是列表
我不知道如何修复这个错误,有人能帮我吗

另外,如果你能,你能给我一些建议来改进整个代码的任何部分吗


*这是我的第一个问题,如果我说得太多,请原谅我“

您应该按照以下步骤来做:

if all(i in word for i in all_letters):
    print("Well done, you got it.")
else:
    print("Sorry, You are the loser.")

这将打印
“做得好,你做到了。”
仅当所有字母都在word中时。它使用
所有内置的

为什么要对范围(1)中的i执行
?向我们展示完整的堆栈跟踪。@user2357112所以每个变量接受一个字母不管你认为循环在做什么,它可能没有做什么。循环完全等同于根本没有循环,只需设置
i=0
@user2357112我不确定该做什么,这是我让我的刽子手游戏给出答案的唯一方法输入的每个字母的ponse。