0
form = input("Please input your form name: ")
while form != "St Albans"or"York"or"Rochester"or"Rochester 2":
    form = input("Please input your form name: ")


Why isnt this working?

It keeps on repeating itself no matter what, it is because of the "or"'s?

  • `x == y or z` does not break down as `x == y or x == z`, it breaks down as `(x == y) or z`. In this case your `z` is a string, but python casts that to a bool because it's appearing as an operand to a boolean operation. Python treats non-empty strings as `True`, so this always evaluates as `True` – Edward Peters Dec 06 '22 at 19:15
  • The problems are with the or statements, if anything is not, it's going inside. So it might not match with `St Albans` but may match with `York`, still it will go in for the or. Or means if any one of them is true - do it. You can solve this with a list though - `ignore_words = ["St Albans", "York", "Rochester", "Rochester 2"]`, And - `if not form in ignore_words: print("No it got ignored") ` – ashraf minhaj Dec 06 '22 at 19:19

0 Answers0