python中主函数循环,带有菜单函数的Python主函数循环不起作用?
我現(xiàn)在是一名大學(xué)生,正在上python課程。我們的任務(wù)是用函數(shù)創(chuàng)建這個(gè)程序。main函數(shù)調(diào)用菜單,然后在main函數(shù)中編寫一個(gè)循環(huán),根據(jù)菜單函數(shù)中的用戶響應(yīng)訪問其他函數(shù)。在
我好像不能讓我的循環(huán)工作。當(dāng)我選擇一個(gè)菜單選項(xiàng)時(shí),什么都不會(huì)發(fā)生?,F(xiàn)在,我只有print語句來測試函數(shù)的調(diào)用。在我編寫函數(shù)之前,我要確保它能正常工作。在
如果有人有一個(gè)循環(huán)調(diào)用函數(shù)應(yīng)該是什么樣的示例,這將對我有很大幫助。在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()
總結(jié)
以上是生活随笔為你收集整理的python中主函数循环,带有菜单函数的Python主函数循环不起作用?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MATLAB资源安装免费激活完整步骤
- 下一篇: 追寻终极数据库 - 事务/分析混合处理系