Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Data Science by (18.4k points)

My python code is stuck in a loop. I have tried making it break. But that has not helped.

It is below:

Adetails = input("Enter flight details (Please enter the three-letter code for the UK airport): ")

while Adetails != "LPL" or "BOH":

    Adetails = input("Error three letter airport code invalid. Please enter either LPL or BOH: ")

Any help would be appreciated.

1 Answer

0 votes
by (36.8k points)
edited by

This is not the correct syntax to test the or condition:

while Adetails != "LPL" or "BOH":

It must be written like this to work (and notice that we need to use and here, not or!)

while Adetails != "LPL" and Adetails != "BOH":

Or equivalently:

while Adetails not in ("LPL", "BOH"):

Do check out Python Data Science Course which helps you understand from scratch  

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...