3
    shift = raw_input("Enter the shift the employee works in:  ")
    shift = shift.upper()
    print shift
    while (shift != "A" or shift != "B" or shift != "C" ):
        shift = raw_input("Invalid Input- Please Enter a, b or c:  ")
        shift = shift.upper()

I need to validate that the user is choosing "a, b or c" I also must use string.upper(). However, it keeps going into the while loop even when I input "a, A, b, B, c or, C" I have the "print shift" to make sure it's inputing correctly and it is.

When I only have "shift != "A"" and type in "a or A" it won't go into the loop. It's only when I add the "B and C" that it starts to mess up. How do I fix this?

1 Answer 1

2

You need to use and instead of or (because x != 1 or x != 2 is always true):

while (shift != "A" and shift != "B" and shift != "C" ):

But you can do better:

while shift not in "ABC":
Sign up to request clarification or add additional context in comments.

1 Comment

the way I remember this is that OR seeks out the first 'Truth' and AND seeks out the first 'Falsehood'. "or truth and lies"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.