Issues with if, else and elif

Viewed 61

I am new to python and have currently hit a roadblock in my code. I know this may be way too obvious to notice but I couldn't get it around my head. I am currently trying to write a code as to asking a bunch of questions and letting the user know what to do during a pandemic, and only accepts the user to enter y or n and if the user enters anything else, the code will ask the user to enter again

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

There are more that I will be adding into the code for further steps but currently when I typed in y, it will just keep printing "Please enter y/n" and keep asking "Did you receive a Health Risk Warning(HRW) Notice (y/n)". What exactly is the issue here? Thanks in advance!

1 Answers

The operation == returns if a value is equal to another value, such as if the input string is strictly equal to yes. Because you want to test if it’s in the list, you should use in:

if HRW in yesChoice:
    doSomething()
Related