if、else 和 elif 的问题

Diy*_*iya 1 python if-statement while-loop

我是 python 新手,目前在我的代码中遇到了障碍。我知道这可能太明显而难以注意到,但我无法理解它。我目前正在尝试编写一段代码来询问一堆问题并让用户知道在大流行期间该做什么,并且只接受用户输入 y 或 n,如果用户输入其他任何内容,代码将询问用户再次输入

yesChoice=["y", "Y"]
noChoice=["n", "N"]
while True:
    HRW=input("Did you receive a Health Risk Warning(HRW) Notice (y/n)?: ")
    if HRW==yesChoice:
        print("Follow protocol of 3-5 days of monitoring, test ART within 24 hrs")
    elif HRW==noChoice:
        well=input("Are you feeling well (y/n)?: ")
        if well==noChoice:
            print("Visit a doctor to assess on the next step")
        else:
            print("For safety measures, please do an ART test")
    else:
        print("Please enter y/n")
        continue
Run Code Online (Sandbox Code Playgroud)

我将在代码中添加更多内容以进行进一步的步骤,但目前当我输入 y 时,它只会继续打印“请输入 y/n”并继续询问“您是否收到健康风险警告(HRW)通知(是/否)”。这里到底是什么问题?提前致谢!

Byt*_*ime 5

==如果一个值等于另一个值,例如输入字符串严格等于 ,则该操作返回yes。因为你想测试它是否\xe2\x80\x99s 在列​​表中,你应该使用in

\n
if HRW in yesChoice:\n    doSomething()\n
Run Code Online (Sandbox Code Playgroud)\n