如何在python 3中将菜单连接在一起并在它们之间导航



我对python比较陌生。

下面是我一直在编写的代码的一部分目前发生在我身上的主要问题是,我无法在主菜单和我创建的其他菜单之间导航。当我尝试时,它只进入下一个菜单,直到它完成程序。

def main():
menuSelect = ""
print("tPersonal Date, Gadget Inventory, Exit")
#main menu
print ("nttWelcome Admin!")
print("nttMain Menu")
print("t1. Personal Data")
print("t2. Gadget Inventory")
print("t3. Quit")
menuSelect = int(input("nPlease select one of the Three options "))
while menuSelect < 1 or menuSelect > 3:
print("The selection provided is invalid.")
menuSelect = int(input("nPlease select one of the three options "))
if menuSelect == 1:
personalData()
elif menuSelect == 2:
gadgetInventory()
elif menuSelect == 3:
quit()

#personal data Menu
def personalData():
menuSelect == ""
print("tCreate New, Current Users, Salary Calculator, Main Menu")

#personal data menu
print ("nttHello Admin!")
print("nttPersonal Data")
print("t1. Create New")
print("t2. Current Users")
print("t3. Salary Calculator")
print("t4. Main Menu")
menuSelect = int(input("nPlease select one of the four options "))
while menuSelect < 1 or menuSelect > 4:
print("The selection provided is invalid.")
menuSelect = int(input("nPlease select one of the four options "))
if menuSelect == 1:
createNew()
elif menuSelect == 2:
currentUsers()
elif menuSelect == 3:
salaryCalculator()
elif menuSelect == 4:
main()
#quit menu
def quit():
again = ""
if again=="yes" or again=="y":
input('Press ENTER to exit')    
else:
main()


main()

我快速查看了您的代码,您的代码行是正确的,但我认为结构不同步,例如第一次选择3不会退出程序。如果你尝试过在像Thonny这样的IDE中逐步执行该程序,它将向你展示你的程序是如何分支的。我没有试图为您解决问题,因为您可以做到这一点,您只需要做一些伪代码来确定您希望程序如何通过其操作流动。

相关内容

最新更新