Write a python program that allows the user to enter the total rainfall for each
ID: 3713402 • Letter: W
Question
Write a python program that allows the user to 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, and the months with the highest and lowest rainfall amounts.
Data:
January 7.9 inches
February 10.1 inches
March 3.4 inches
April 6.7 inches
May 8.9 inches
June 9.4 inches
July 5.9 inches
August 4.1 inches
September 3.7 inches
October 5.1 inches
November 7.2 inches
December 8.3 inches
Explanation / Answer
year=[] #List to save all the rainfall values
print 'Please enter Jan rainfall in inches(Enter only values): '
jan=float(input())
print 'Please enter Feb rainfall in inches(Enter only values): '
feb=float(input())
print 'Please enter Mar rainfall in inches(Enter only values): '
mar=float(input())
print 'Please enter Apr rainfall in inches(Enter only values): '
apr=float(input())
print 'Please enter May rainfall in inches(Enter only values): '
may=float(input())
print 'Please enter Jun rainfall in inches(Enter only values): '
jun=float(input())
print 'Please enter Jul rainfall in inches(Enter only values): '
jul=float(input())
print 'Please enter Aug rainfall in inches(Enter only values): '
aug=float(input())
print 'Please enter Sep rainfall in inches(Enter only values): '
sep=float(input())
print 'Please enter Oct rainfall in inches(Enter only values): '
oct=float(input())
print 'Please enter Nov rainfall in inches(Enter only values): '
nov=float(input())
print 'Please enter Dec rainfall in inches(Enter only values): '
dec=float(input())
#list of month names in sequence
months=("January","February","March","April","May","June","July","August","September","October","November","December")
#append all the rainfall values in list
year.extend((jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec))
#Function of lowest rainfall month
def lowest():
print('The minimum rainfall is', min(year))
monthIndex=year.index(min(year))
print('Month with minimum rainfall is',months[monthIndex])
lowest()
#Function of highest rainfall month
def highest():
print('The most rainfall is', max(year))
monthIndex=year.index(max(year))
print('Month with most rainfall is',months[monthIndex])
highest()
#Function showing total rainfall
def total():
print('The total rainfall is', sum(year))
total()
#function showing average monthly rainfall
def average():
print('The average rainfall is', float(sum(year))/len(year))
average()
Note: This is your executable prgram.Please rate me +ve if found helpful
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.