python-3.x - 如何在 python 3 中将菜单连接在一起并在它们之间导航?
问题描述
我对python比较陌生。
波纹管是我一直在处理的代码的一部分目前对我来说发生的主要问题是我无法在主菜单和我创建的其他菜单之间导航。当我尝试它时,它只会进入下一个菜单,直到它完成程序。
def main():
menuSelect = ""
print("\tPersonal Date, Gadget Inventory, Exit")
#main menu
print ("\n\t\tWelcome Admin!")
print("\n\t\tMain 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 ("\n\t\tHello Admin!")
print("\n\t\tPersonal 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 中单步执行程序,它会向您展示您的程序是如何分支的。我没有尝试为您解决问题,因为您可以做到,您只需要执行一些伪代码来确定您希望程序如何通过其操作进行流程。
推荐阅读
- java - PreferenceFragmentCompat Fragment 在充气后活动 OnCreate 期间具有 mPreferenceManager null
- java - IndexOutOfBounds 异常将项目添加到 ArrayList
- python - WinError5 - Python 无法安装 sci-learn、sci-kit 或 sci-py
- mysql - 在表中添加一列以计算 MySQL 的最早日期
- javascript - 如何使用 angularJS 在 HTML 中显示我的请求 response.value
- django - 如何从 vue.js 中的请求中获取 DRF 中的 self.request.user?
- asp.net-core-mvc - 在 asp.net core mvc 中实现从内部布局搜索
- javascript - JS 错误:错误:参数“可取消”需要 GCancellable 类型的对象,但得到了字符串类型
- php - PHP仅在其他索引匹配时按列过滤多维数组
- python-3.x - Chromedriver 使用 Docker 文件安装,但 chrome 驱动程序未反映在上述目录中