我是 Python 新手,一直在尝试创建一个简单的菜单,当用户按 4 时退出程序。如果用户立即选择 4,则菜单可以工作,但如果用户在按 4 之前选择其他选项,则 while 循环不会不会中断,菜单会继续。有什么想法可以更改它以便菜单正确退出吗?
def main():
print('''
Welcome to Grade Central
[1] - Enter Grades
[2] - Remove Student
[3] - Student Average Grades
[4] - Exit
\n
''')
action = int(input("What would you like to do today? \n"))
if action == 1:
print(1)
elif action == 2:
print(2)
elif action == 3:
print(3)
elif action == 4:
print("The program has been exited")
else:
print("Invalid input! Please select an option")
return action
while main() != 4:
main()
白衣非少年
慕容708150
FFIVE
繁花不似锦
相关分类