Why is my while loop with python not working?

56 views Asked by At

I wrote this code to ask the user for options A, B, or C and show a message afterward, but even if I type the correct options, it still sends me the 'try again' message. what can I do so the program runs correctly

option = str(input('\nChoose A, B or C: '))
while option.lower() != 'A' or 'B' or 'C':
    print('\nThat option is not availible, try again')
    option = str(input('\nChoose A, B or C'))
if option.lower() == 'A' or 'B' or 'C':
    print(f'You chose: {option}')

I was expecting the program to return the letter I choose only if it is A, B or C. otherwise print the 'try again message'

1

There are 1 answers

0
SIGHUP On

You could use a construct like this to ensure that the option is either A, B or C (case-insensitive):

while (option := input("\nChoose A, B or C: ")).lower() not in set("abc"):
    print('\nThat option is not available, try again')

print(f"You chose option {option}")