Ask 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 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.

+3
Answers (1)
  1. 5 July, 14:33
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers