Answer:
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)
Step-by-step 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