# CIS 122 # Ch.5 Program Ex 7: Average Rainfall. # Written by Lee Her. # Last modified on 04/23/2015 #Input years of rainfall to calculate years = int(input("Enter number of years? ")) print years print #Determine monthly rainfall totalrainFall = 0 for year in range(1, 1+years): for month in range(1, 13): periodrainFall = float(input('Inches of rainfall for year {}'.format(year)+', month {}'.format(month)+': ')) print periodrainFall totalrainFall += periodrainFall #Calculate total months and average totalMonths = years*12 avgrainfall = totalrainFall/totalMonths print #Display Results print 'Number of months: {}'.format(totalMonths) print 'Total Rainfall: {} inches.' .format(totalrainFall) print 'Average Rainfall per month: {} inches.' .format(avgrainfall) #End
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question