저는 현재 파이썬 수업을받는 대학생입니다. 우리의 임무는이 프로그램을 함수로 만드는 것입니다. 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()
감사합니다. 매우 도움이되었습니다. 그것은 작동! 예! – ChobitsMng