In: Computer Science
Design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts.
Design a program to solve Chapter 8 Programming Exercise 3
(Rainfall Statistics) in your textbook. Create parallel arrays for
the month names and rainfall amounts for each month. Use month
names (i.e. January, February, March, etc.) when printing out the
months with the highest and lowest amounts. Include a modular (no
global variables or constants) approach that includes and uses (at
least) a main module and the following functions:
• GetLargestRainfall takes parameters of the array of rainfall
statistics and the size of the array. Returns the index of the
array element with the largest rainfall
• GetSmallestRainfall takes parameters of the array of rainfall
statistics and the size of the array. Returns the index of the
array element with the smallest rainfall
1- create IPO chart for GetLargestRainfall funcation and GetSmallestRainfall function.
2- create the properly aligned textbook fromat pseudocode.
3- Create the python source code, that represent the pseudocode requirements.
def GetLargestRainfall(rainfall,size):
maxfall=rainfall[0]
for i in range(size):
if(rainfall[i]>maxfall):
maxfall=rainfall[i]
for i in range(size):
if(rainfall[i]==maxfall):
break
return str(i)+" "+str(maxfall)
def GetSmallestRainfall(rainfall,size):
minfall=rainfall[0]
for i in range(size):
if(rainfall[i]<minfall):
minfall=rainfall[i]
for i in range(size):
if(rainfall[i]==minfall):
break
return str(i)+" "+str(minfall)
def main():
rainfall=[]
for i in range(12):
a=float(input())
rainfall.append(a)
sum=0.0
for i in rainfall:
sum+=i
avg=sum/12
monthName=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
for i, j in zip(monthName, rainfall):
print(i,j)
print("Average monthly rainfall: ",avg)
print("Smallest rainfal: ",GetSmallestRainfall(rainfall,12))
print("Largest rainfall: ",GetLargestRainfall(rainfall,12))
if __name__ == "__main__":
main()
I have attached the source code with output.
Working is simple as asked in the question.
Input Output are same as asked in the question.
For IPO chart and pseudo code I would advise you to do it, as I
have already attached the source code and ouput respectively.
Apart from these things, I suggest you to run this program once for
better understanding.
I hope it helps.