私は現在、パイソンクラスを受講中の大学生です。私たちの任務は、このプログラムを関数で作成することです。メイン関数はメニューを呼び出し、メイン関数にループを書き込んで、メニュー関数のユーザー応答に基づいて他の関数にアクセスします。メニュー機能を持つPythonのメイン関数ループが機能していませんか?
私のループが機能しないようです。メニューオプションを選択すると何も起こりません。今のところ、関数の呼び出しをテストするための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()
ありがとうございましたできます!!わーい! – ChobitsMng