Done = False
while not Done:
print('S Start New Order')
print('E Edit Order')
print('P Print Bill')
print('R Receive Payment')
print('M Manager Report')
print('Q Quit')
print('-----------------')
Command = ''
while Command == '':
Command = input("Enter Choice> ")
Command = Command.strip().upper()
if Command[0] == 'S':
print('Start New Order:')
elif Command[0] == 'E':
print('Edit Order:')
elif Command[0] == 'P':
print('Print Bill:')
elif Command[0] == 'R':
print('Recieve Payment:')
elif Command[0] == 'M':
print('Manager Report:')
elif Command[0] == 'Q':
print('Quit:')
我想这样做当有人输入例如“j”或“34”时,它会跳回“Enter Choice”并且不会再显示整个菜单。
答案 0 :(得分:3)
e.g。
while Command not in ['S', 'E','P', 'R', 'M', 'Q']:
Command = raw_input("Enter Choice> ")
Command = Command.strip().upper()
break
选项时,请使用Q
语句。或设定值Done = True
e.g。
elif Command[0] == 'Q':
print('Quit:')
break
OR
elif Command[0] == 'Q':
print('Quit:')
Done = True
答案 1 :(得分:1)
摆脱第1行和第2行,因为“完成”不用于任何事情。在底部添加另一行“Command =''”与“elseif”对齐以删除陈旧输入。首先,它打印出标题内容,然后循环询问输入,然后处理输入,然后返回循环开始。