-2

here is the code I am trying to fix: the program runs but never returns covid negative even if I answer with a no, what would the correct syntax be to write this statement?

elif question1 and question2 and question3 and question4 and question5 and question6 == "NO":
    print(name)
    print(gender)
    print(number)
    print(adress)
    print("COVID-19 Negative")
    neg_counter = neg_counter + 1
  • Looks like this might help you https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value – DJSchaffner Aug 10 '20 at 18:52
  • It must be because this clause is skipped by a previous if returning true, can you paste the full if statement? – RichieV Aug 10 '20 at 18:52

1 Answers1

1

Your code actually won't properly run at all – it'll compute as something like this:

(((question1 and question2) and question3) and question4)...

As in it's not actually calculating what I think you want, which is to see if any of them are =="NO".

One way to do this is:

elif "NO" in (question1, question2, question3, question4, question5, question6):

EDIT: Since OP has clarified and wants to check if all of them are =="NO" or not, we can do this:

elif question1 == question2 == question3 == question4 == question5 == question6 == "NO":
M Z
  • 4,571
  • 2
  • 13
  • 27
  • I am not trying to see just if any of them are == "NO" but to see if ALL of them are == "NO". That's why I used all those and statements. How would I be able to check if all of them were == "NO" – Akhil Metukuru Aug 10 '20 at 19:55