#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 def initialise(): 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 """ ) initialTotal = 0 initialValueOfN = 0 return (initialTotal, initialValueOfN) def promptForNumbers(): print("Please enter first number ") num1 = int(input()) print("Please enter second number ") num2 = int(input()) print("Please enter third number ") num3 = int(input()) return (num1,num2,num3) def findMax(number1, number2, number3): maxnumber = number1 if number2>maxnumber: maxnumber = number2 if number3>maxnumber: maxnumber = number3 #endif print ("Max of the three numbers is is ",maxnumber) return (maxnumber) def performCalculations(total,n, maxNum): total = total + maxNum n=n+1 return (total,n) def processData(total, numEntries): num1, num2, num3 = promptForNumbers() n=numEntries while num1!=0 and num2!=0 and num3!=0: maxNum = findMax(num1,num2,num3) total, n = performCalculations(total, n,maxNum) num1, num2, num3 = promptForNumbers() return (total,n) #endwhile def calculateAverage(totalOfMaximums, n): average = totalOfMaximums/n print ("Average of maximums =",round(average,1)) #Main program total, n = initialise() total, n = processData(total,n) calculateAverage(total, n)