Python 拼字游戏中的功能不起作用-MIT 6.0001 P集3

Python 拼字游戏中的功能不起作用-MIT 6.0001 P集3,python,python-3.x,Python,Python 3.x,我不明白为什么我的麻省理工学院6.0001,PS3,问题3的代码允许一只手的字母数量不足,例如:对于单词“Rapture”,当我在游戏中测试它时,我用字母{'r':1,'a':3,'p':2,'e':1,'t':1,'u':1}/code>得到True。但是,当我单独输入代码时,得到的是False 下面是游戏中的代码 if l_word in word_list: in_list = True else: in_list = False # Make word into lis

我不明白为什么我的麻省理工学院6.0001,PS3,问题3的代码允许一只手的字母数量不足,例如:对于单词“Rapture”,当我在游戏中测试它时,我用字母
{'r':1,'a':3,'p':2,'e':1,'t':1,'u':1}/code>得到
True
。但是,当我单独输入代码时,得到的是
False

下面是游戏中的代码

if l_word in word_list:
    in_list = True
else:
    in_list = False

# Make word into list
w_holder = []
for let in l_word:
    w_holder.append(let)

# Compare word to hand
for let in w_holder:
    if let in h_holder:
        h_holder.pop(let)
        can_make = True
    else:
        can_make = False

if in_list is True and can_make is True:
    return True
else:
    return False
下面是我用来将其作为单独模块进行测试的代码:

word = "Rapture"
hand = {'r': 1, 'a': 3, 'p': 2, 't': 1, 'u': 2}

word_list = ["hot", "day", "face", "holl", "rapture", "honey"]

# Declare variables
l_word = word.lower()
h_holder = hand.copy()
can_make = ""

if l_word in word_list:
    in_list = True
else:
    in_list = False

# Make word into list
w_holder = []
for let in l_word:
    w_holder.append(let)

# Compare word to hand
for let in w_holder:
    if let in h_holder:
        h_holder.pop(let)
        can_make = True
    else:
        can_make = False

if in_list is True and can_make is True:
    print("True")
else:
    print("False")

print("Can make is" , can_make)
print("In list is" , in_list)

“不起作用”不够具体。请回答您的问题,并准确描述问题是什么。谢谢你的反馈。让我知道我发布的内容是否有意义。这绝对是一个进步。有一件事我不明白,代码中的注释是
#将单词编入字典
,但变量
w\u holder
是一个列表,而不是字典。注释应该是“list”。我从一本字典开始,但我改成了一个列表,因为我觉得它也很管用。我不确定这是否是错误的,但我会在上面编辑。瑞利:在你问题的第二段代码中,什么打印值是错误的?当我如图所示运行它时,它会说
can\u make
False
,如果我在
hand
中添加一个
'e'
,它会说
can\u make
True
,这似乎是正确的。