Ad

While Loop Still Looping

- 1 answer

I need to have 'F' or 'M' as input from the user. So there is my code :

a = input("")
while a != 'F' or a != 'M':
    a = input("")

But it still looping even if the user enter 'M' or 'F' or anything else. so I've tried this :

genre = input("")
while genre != 'F':
    genre = input("")

And it works.. I just need to have 'M' OR 'F', could someone help me with this?

Thank's in advance

Ad

Answer

You need and instead of or

while a != 'F' and a != 'M'

because a can't be equal to two things at a time. As it is now, if a=='M', then a != 'F', so the loop continues (the same for the reverse values). So, the loop will never end.

Ad
source: stackoverflow.com
Ad