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”时,它会跳回“输入选择”并且不会再次显示整个菜单。
最佳答案
- 我们必须检查输入的值。
例如
while Command not in ['S', 'E','P', 'R', 'M', 'Q']:
Command = raw_input("Enter Choice> ")
Command = Command.strip().upper()
- 当用户进入菜单的
Q
选项时使用break
语句。或设置Done = True
的值
例如
elif Command[0] == 'Q':
print('Quit:')
break
或
elif Command[0] == 'Q':
print('Quit:')
Done = True
关于python - 如何让程序回到 "menu"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28428000/