如果以下4个字母E
/ A
/ S
/ T
是我的运营商,我该怎么做才能让用户输入无效的运营商。基本上除了下面列出的任何东西?
print("Available Operators:")
print("'E' sets starting number")
print("'A' for addition")
print("'S' for subtraction")
print("'T' will terminate program")
# Prompt user to select the operator
choice = input("Select Operator (e/a/s/t): ")
答案 0 :(得分:0)
您可以使用in
来测试选项列表:
direction = input()
if direction in 'NESW':
# valid input
else:
# invalid input
答案 1 :(得分:0)
valid_entries = {'E', 'A', 'S', 'T'}
while True:
result = input()
if result in valid_entries:
break
print('Please enter a valid letter')