Question

In: Computer Science

Design a program that lets the user enter the total rainfall for each of 12 months...

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.

Requirements

You must use the given function prototypes. You can add more functions if you like.

def get_total_rainfall(months, months_len):

def get_average_monthly_rainfall(months, months_len):

def get_month_with_highest_rainfall(months, months_len):

def get_month_with_lowest_rainfall(months, months_len):


Design Considerations

Use a global parallel array of month names to associate with the monthly rainfall:

MONTH_NAMES = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']

The function get_average_monthly_rainfall(months, months_len)may call the function get_total_rainfall(months, months_len

Use the techniques we’ve learned in class. Specifically, avoid (for now) the Python commands:

sum(t)

for index,month in enumerate(months):

Example Run

Please enter the rainfall for month [ January ]

15.5

Please enter the rainfall for month [ February ]

17.2

Please enter the rainfall for month [ March ]

18.0

Please enter the rainfall for month [ April ]

22.2

Please enter the rainfall for month [ May ]

15.9

Please enter the rainfall for month [ June ]

2.2

Please enter the rainfall for month [ July ]

0

Please enter the rainfall for month [ August ]

0

Please enter the rainfall for month [ September ]

2.1

Please enter the rainfall for month [ October ]

8.5

Please enter the rainfall for month [ November ]

12.0

Please enter the rainfall for month [ December ]

15.5

Total Rainfall: 129.10000000000002

Average Monthly Rainfall: 10.758333333333335

Month with highest rainfall: April

Month with lowest_rainfall: July

Solutions

Expert Solution

Hi,

Please find the answer below:
-------------------------------

Python Program:
## Function to get user input
def getInputFromUser(months,MONTH_NAMES,months_len):
    for i in range(months_len):
        months.append(float(input("Please enter the rainfall for month [" + MONTH_NAMES[i] + "]\n")))

## Function to get total rainfall
def get_total_rainfall(months, months_len):
    totalRain = 0
    for i in range(months_len):
        totalRain +=months[i] # add month rainfalls
    return totalRain

## Function to get average monthly rainfall
def get_average_monthly_rainfall(months, months_len):
    return float(get_total_rainfall(months, months_len)/months_len)

## Function to get higest rainfall month array index
def get_month_with_highest_rainfall(months, months_len):
    highestRain = -99999 #arbitrary min value
    highestArrayIndex = 0
    for i in range(months_len):
        if highestRain < months[i]:
            highestRain = months[i] #track highest rain
            highestArrayIndex = i
    return highestArrayIndex

## Function to get lowest rainfall month array index
def get_month_with_lowest_rainfall(months,months_len):
    lowestRain = 99999 #arbitrary max value
    lowestArrayIndex = -1
    for i in range(months_len):
        if lowestRain > months[i]:
            lowestRain = months[i] #traCL lowest rain
            lowestArrayIndex = i
    return lowestArrayIndex


## main function
def main():
    #variables
    months = []
    months_len=12
    MONTH_NAMES = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
    #Invoke to get user data for the rainfalls
    getInputFromUser(months,MONTH_NAMES,months_len)
    #Invoke functions and print data
    print("Total Rainfall: " + str(get_total_rainfall(months,months_len)))
    print("Average Monthly Rainfall: " + str(get_average_monthly_rainfall(months,months_len)))
    largest = get_month_with_highest_rainfall(months,months_len)
    print("Month with highest rainfall: " + MONTH_NAMES[largest])
    smallest = get_month_with_lowest_rainfall(months,months_len)
    print("Month with lowest_rainfall: " + MONTH_NAMES[smallest])

main()


Code Indentation Screen:


Sample Program Output:

Please enter the rainfall for month [January]
15.5
Please enter the rainfall for month [February]
17.2
Please enter the rainfall for month [March]
18.0
Please enter the rainfall for month [April]
22.2
Please enter the rainfall for month [May]
15.9
Please enter the rainfall for month [June]
2.2
Please enter the rainfall for month [July]
0
Please enter the rainfall for month [August]
0
Please enter the rainfall for month [September]
2.1
Please enter the rainfall for month [October]
8.5
Please enter the rainfall for month [November]
12.0
Please enter the rainfall for month [December]
15.5
Total Rainfall: 129.10000000000002
Average Monthly Rainfall: 10.758333333333335
Month with highest rainfall: April
Month with lowest_rainfall: July


Screenshot:

-------------------------------

Hope this helps.
Let me know if you need more help with this.
Kindly, like the solution, if you find it useful
Thanks.


Related Solutions

Design a program that lets the user enter the total rainfall for each of 12 months...
Design a program that lets the user enter the total rainfall for each of 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the months with the highest and lowest amounts. This is my Pthon 3.8.5 code so far: #Determine Rainfall Program for a 12 month Period #It should calculate and output the "total yearly rainfall, avg monthly rainfall, the months with highest and lowest amounts #list of...
design a program that lets the user enter the total rainfall for each of 12 months...
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.   ---->>> Enhance the program so it sorts the array in ascending order and displays the values it contains. You can choose which sorting algorithm to use (bubble sort, selection sort, or insertion sort). Depending on your...
Design a program that lets the user enter the total rainfall for each of 12 months...
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.)...
In Python: Design a program that lets the user enter the total rainfall for each of...
In Python: Design a program that lets the user enter the total rainfall for each of the 12 months into a list. The program should calculate and display the total rainfall for the year, the average monthly rainfall, the months with the highest and lowest amounts. However, to start, do not ask the user for input. Instead, hard code the monthly rainfalls as a list in your program, and then use the list to determine how to conduct the processing...
In python please design a program that lets the user enter the total rainfall for each...
In python please design a program that lets the user enter the total rainfall for each of the last 10 years into an array. The program should calculate and display the total rainfall for the decade, the average yearly rainfall, and the years with the highest and lowest amounts. Should have Indentation Comments Good Variables initializations Good questions asking for the parameters of the code Output display with explanation Screenshot
Write a C++ program that lets the user enter the total rainfall for each of 12...
Write a C++ program that lets the user enter the total rainfall for each of 12 months (starting with January) into an array of doubles. The program should calculate and display (in this order): the total rainfall for the year,     the average monthly rainfall,     and the months with the highest and lowest amounts. Months should be expressed as English names for months in the Gregorian calendar, i.e.: January, February, March, April, May, June, July, August, September, October, November,...
DESIGN A FLOWCHART IN FLOWGORITHM Rainfall Statistics Design a program that lets the user enter the...
DESIGN A FLOWCHART IN FLOWGORITHM Rainfall Statistics 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. PLEASE AND THANK YOU
Write a C++ console application that allows your user to enter the total rainfall for each...
Write a C++ console application that allows your user to enter the total rainfall for each of 12 months into an array of doubles. The program should validate user input by guarding against rainfall values that are less than zero. After all 12 entries have been made, the program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts.
Write a program that asks the user to enter the total precipitation for each of the...
Write a program that asks the user to enter the total precipitation for each of the twelve months of the year into a list. The program should calculate and display the total precipitation for the year, the average monthly precipitation, and the months with the highest and lowest precipitation amounts. FYI: precipitation is measured in inches. Assume that precipitation amounts are floating-point numbers. You will need a list to store the precipitation amounts and another list to store the names...
How to write a C++ program that lets the user enter a string and checks if...
How to write a C++ program that lets the user enter a string and checks if it is an accepted polynomial. Accepted polynomials need to have one term per degree, no parentheses, spaces ignored.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT