Ask Question
22 August, 18:12

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. Name 'Search Modify the Sorted Names' program that you wrote for this exercise.

+1
Answers (1)
  1. 22 August, 19:53
    0
    rainfalls = []

    for i in range (12):

    rain = float (input ("Enter rainfall: "))

    rainfalls. append (rain)

    total = 0

    highest = rainfalls[0]

    lowest = rainfalls[0]

    highest_index = 0

    lowest_index = 0

    for i in range (len (rainfalls)):

    total + = rainfalls[i]

    if rainfalls[i] > = highest:

    highest = rainfalls[i]

    highest_index = i

    if rainfalls[i] < = lowest:

    lowest = rainfalls[i]

    lowest_index = i

    average = total / 12

    print ("Total rainfall: " + str (total))

    print ("The average rainfall: " + str (average))

    print ("Highest: " + str (highest_index + 1))

    print ("Lowest: " + str (lowest_index + 1))

    rainfalls. sort ()

    print (rainfalls)

    Explanation:

    Create a list for rainfall values called rainfalls

    Get the values from the user and put them in the rainfalls using a for loop

    Create another for loop that iterates through the rainfalls. Add each value to the total. Find the highest and lowest month and their index using if else structure.

    When the loop is done, calculate the average. Print the total, average and the index of the months with highest and lowest amount. Then, sort the list using sort () function and print the values
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “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 ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers