#Structured Programming Worksheet 2 Question 4 #program to find the maximums of sets of three numbers #until the user enters three zeroes #It then calculates and outputs the average of the maximums #written as a series of subroutines, but uses global variables #see max as subs local vars.py for a version passing parameters #and using no global variables def initialise(): global total, n print ( """ program finds the maximums of sets of three numbers.\n Enter three zeroes when all numbers entered.\n Proram then calculates and outputs the average of the maximums """ ) total = 0 n = 0 def promptForNumbers(): global num1, num2, num3 print("Please enter first number ") num1 = int(input()) print("Please enter second number ") num2 = int(input()) print("Please enter third number ") num3 = int(input()) def findMax(): global num1, num2, num3,maxnum maxnum = num1 if num2>maxnum: maxnum = num2 if num3>maxnum: maxnum = num3 #endif print ("Max of the three numbers is is ",maxnum) def performCalculations(): global total, n, maxnum total = total + maxnum n=n+1 def processData(): global num1, num2, num3, total, n, maxnum promptForNumbers() while num1!=0 and num2!=0 and num3!=0: findMax() performCalculations() promptForNumbers() #endwhile def calculateAverage(): global total, n average = total/n print("Average of maximums is ",average) #Main program initialise() processData() calculateAverage()