我编写这段代码是为了询问用户选项 A、B 或 C,然后显示一条消息,但即使我输入了正确的选项,它仍然会向我发送“重试”消息。我该怎么做才能使程序正确运行
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}')
我希望程序仅在 A、B 或 C 时返回我选择的字母。否则打印“重试消息”
您可以使用这样的构造来确保选项是 A、B 或 C(不区分大小写):
while (option := input("\nChoose A, B or C: ")).lower() not in "abc":
print('\nThat option is not available, try again')
print(f"You chose option {option}")