python - 进入python中的下一个菜单选项
问题描述
我有一个关于菜单以及如何进行“选项 __ 进度”选项的问题(请注意,我对 Python 很陌生,所以这可能是一个非常容易解决的问题,我只是没有搜索到正确的东西)。在我当前的代码中,我可以让用户选择其中包含活动的 4 个选项之一。选项 C 和 D 的一部分使用来自选项 B 的数据(但无需执行选项 B 就可以对用户可见,只是作为各种信息中心,而不是计算)。我编写了一些代码来显示我在下面谈论的内容:
def printMenu ():
print("Activity List")
print("A: Standalone Activity - What is the weather like")
print("B: Events")
print("C: Times")
print("D: Olympic Standards")
print("X: Exit")
return input("Please choose a selection: ").upper()
def main():
choice = printMenu()
choice
def program(selection):
if selection == "A":
print("The weather is not important, as I am a computer")
elif selection == "B":
eventInfo = input("What is your best event and distance: ")
def sportMenu():
print("1. Return to Main Menu")
print("2. Choose another sport")
print("3. Continue to Part C: Countries")
print("ENTER. Close application")
sportMenu()
sportsMenu = input("Please select an option: ")
if sportsMenu == "1":
main()
elif sportsMenu == "2":
sports()
elif sportsMenu == "3":
times()
else:
exit()
elif selection == "C":
# information for users who selected option C originally
print("Talking about World Record times in certain events")
# if they selected B and chose an event, this is where they would be sent to
print("You have selected the event: ", eventInfo)
timeInfo = input("Please enter your best time (MM:SS.ss): ")
# same menu as above, sending to main, section B to choose a different event, section D for comparison, or exit program
...
elif section == "D":
# information for users who selected option C originally
print("Talking about top competitor's times in certain events and how younger athletes aspire to reach them, and the benefits of comparing times")
# if they selected B and chose an event, and input a time at C this is where they would be sent to
print("Your time of", timeInfo, "for", eventInfo, "has been compared to the World Record time of ____")
# an external file of all World Record times is then referred to, and compared to the user's input in timeInfo
# menus as above, main, going back to B, or C for different events or times respectively, or exit program
elif selection == "X":
exit()
else:
print("Try again, please ensure the letter is shown in the menu")
selection = printMenu()
while selection != 'X':
program(selection)
print()
selection = printMenu()
我想知道用户是否有办法在选项 B 中输入答案,并直接跳到代码部分,# if they selected B and chose an event, this is where they would be sent to
他们在 B 部分输入的信息(我想存储在 eventInfo 中)?我认为这将是从 C 到 D 的相同过程,并且我几乎就在那里,但显然在想要跳转到它们之前没有定义这些选项,我得到了错误。任何帮助将不胜感激!谢谢
解决方案
推荐阅读
- java - 在 glassfish 上部署时出现异常:ArrayIndexOutOfBoundsException: 9578
- python - 时间序列重采样到 Pandas 中的每周间隔会引发错误
- python - 将索引与列值从一个数据框插入另一个数据框
- c++ - 了解 boost 执行器示例
- reactjs - 在 ReactJS 中初始化状态的不同方法
- html - Laravel 站点在托管后无法正常工作 HTTP 错误 500 无法处理此请求
- regex - 这个不重定向的简单重写规则有什么问题?
- java - 将 XML 响应拆分为页面
- html - 致命错误:未捕获的错误调用未定义的函数 mysql_real_escape_string() HTML/PHPMYADMIN
- arrays - 我得到 ArrayIndexOutOfBoundsException