如何让用户在Python中输入特定单词以获得特定响应

问题描述 投票:0回答:1

我正在尝试做一个简单的测验和Python来判断用户是否能够确定我的朋友是谁。它仍然不完整,但基本上我希望程序根据他们是否输入与我的列表匹配的特定输入来吐出特定的响应/例如第一个问题是如果用户输入我想要的“Mariah”,谁是我最好的朋友程序告诉他们他们是正确的,然后继续下一个问题。我的问题是,当我输入响应应该得到某个响应时,它不匹配。它完全忽略了我的 If 语句是否得到“你的正确!”语句并直接跳转到 else 语句:抱歉您不正确。我该如何解决这个问题

list = ["Mariah", "Julian", "Gabbi"]
variable = input("do you know my friends? yes or no? ")
if variable.lower() == "yes":
    print("oh really... ")
    variable2 = input("what is my best friend's name? ")
    if variable2.lower() == list[0]:
    print("you are correct, but she's not my only friend")
    else:
        print("sorry you're WRONG!")
elif variable.lower() == "no":
     print("i thought so...")
else:
    print("that answer didn't make sense")
python python-3.x if-statement input user-input
1个回答
0
投票

您正在将输入转换为小写,但不是列表值

尝试

if variable2.lower() == list[0].lower():
© www.soinside.com 2019 - 2024. All rights reserved.