Q: 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.
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.
Note: Please answer all the question.
Note: single question with different parts, it just all the information.
Code Snippet:
def GetSmallestRainfall(arr,n):
lowest = arr[0]
lowestIndex = -1
for i in range(n):
if arr[i] <= lowest:
#Calculating lowest rainfall index
lowest =
arr[i]
lowestIndex =
i
return lowestIndex
def GetLargestRainfall(arr,n):
highest = arr[0]
highestIndex = -1
for i in range(n): #Calculating highest rainfall
index
if arr[i] >= highest:
highest =
arr[i]
highestIndex =
i
return highestIndex
def totalRainfall(arr,n):
total = 0
for i in range(n):
total += arr[i] #Calculating
total
return total
def averageMonthlyRainfall(arr,n):
average = totalRainfall(arr,n)/n #average
return average
if __name__ == '__main__':
#Months List
months = ['January', 'February', 'March', 'April',
'May', 'June', 'July','August', 'September', 'October', 'November',
'December']
arr = []
for i in range(12): #Iterating over 12 as there are 12
months
arr.append(float(input('Enter the
Rainfall for %s: ' %months[i])))
n = len(arr) #Length of the array
print("Total rainfall : %d" %(totalRainfall(arr,n)))
#Calling functions
print("Average Monthly Rainfall %.2f"
%(averageMonthlyRainfall(arr,n)))
index = GetLargestRainfall(arr,n)
print("Largest Rainfall %s %.2f"
%(months[index],arr[index]))
index = GetSmallestRainfall(arr,n)
print("Smallest Rainfall %s %.2f"
%(months[index],arr[index]))
Code Snippet:
Output:
IPO Chart:
Input | Processing | Output |
Monthly Rainfall for 12 months in an year. |
Compute the Total Rainfall by adding all the monthly rainfalls. Compute the Average Rainfall by calling the Total Rainfall function and dividing the returned value by the length of the array. Compute the Maximum Rainfall by finding the maximum value of the array. Compute the Minimum Rainfall by finding the minimum value of the array. |
Total Rainfall across all the months. Average Monthly Rainfall. |
Get Answers For Free
Most questions answered within 1 hours.