-1

First post; programming newbie; PYTHON. I'm trying to do the following and having some trouble: If person answers yes, then proceed with the questions, which is a function. If person answers no, then print "Please get the patient" and rerun the question. Any help is GREATLY appreciated!

It proceeds to questions () regardless if the answer is "yes" or "no." I tried using "else" with no success, "elif" without success either.

patient = input("The following are questions are intended for the patient. Are you the patient? (Yes or No)")
if patient == 'yes' or 'Yes' or 'y':
    questions()
elif patient != 'yes' or 'Yes' or 'y':
    print ("Please get the patient.")
S. Liu
  • 3
  • 2

1 Answers1

1

You're using the wrong syntax for testing a string to see if it matches multiple other strings. In the first test, you have:

if patient == 'yes' or 'Yes' or 'y':

You could change this to:

if patient == 'yes' or patient == 'Yes' or patient == 'y':

Or, more concisely, you could use:

if patient in ('yes', 'Yes', 'y'):

For the elif portion, you don't need to repeat the opposite comparison. Just replace the entire elif line with:

else:

If you want to put the whole thing in a loop that exits after successfully calling questions, you could use:

while True:
    patient = input("The following are questions are intended for the patient. Are you the patient? (Yes or No)")
    if patient in ('yes', 'Yes', 'y'):
        questions()
        break
    else:
        print ("Please get the patient.")
Tom Karzes
  • 22,815
  • 2
  • 22
  • 41