python中主函数循环,带有菜单函数的Python主函数循环不起作用?
我現在是一名大學生,正在上python課程。我們的任務是用函數創建這個程序。main函數調用菜單,然后在main函數中編寫一個循環,根據菜單函數中的用戶響應訪問其他函數。在
我好像不能讓我的循環工作。當我選擇一個菜單選項時,什么都不會發生。現在,我只有print語句來測試函數的調用。在我編寫函數之前,我要確保它能正常工作。在
如果有人有一個循環調用函數應該是什么樣的示例,這將對我有很大幫助。在def GetChoice():
#Function to present the user menu and get their choice
#local variables
UserChoice = str()
#Display menu and get choice
print()
print("Select one of the options listed below: ")
print("\tP\t==\tPrint Data")
print("\tA\t==\tGet Averages")
print("\tAZ\t==\tAverage Per Zone")
print("\tAL\t==\tAbove Levels by Zone")
print("\tBL\t==\tBelow Levels")
print("\tQ\t==\tQuit")
print()
UserChoice = input("Enter choice: ")
print()
UserChoice = UserChoice.upper()
return UserChoice
def PrintData():
print("test, test, test")
def AverageLevels():
print("test, test, test")
def AveragePerZone():
print("test, test, test")
def AboveLevels():
print("test, test, test")
def BelowLevels():
print("test, test, test")
def main():
Choice = str()
#call GetChoice function
GetChoice()
#Loop until user quits
if Choice == 'P':
PrintData()
elif Choice == 'A':
AverageLevels()
elif Choice == 'AZ':
AveragePerZone()
elif Choice == 'AL':
AboveLevels()
elif Choice == 'BL':
BelowLevels()
main()
總結
以上是生活随笔為你收集整理的python中主函数循环,带有菜单函数的Python主函数循环不起作用?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MATLAB资源安装免费激活完整步骤
- 下一篇: python怎么创建字符串列表_Pyth