# Average Rainfall # This module calculates the average rainfall over a number of years # Written by Beth Mela # Last updated April 23, 2015 # Define variables and ask user for the number of years of rainfall they want to average totalRainfallInches=0 years=input('Enter the number of years of rainfall to be averaged:') print('The number of years of data to collect is {} years.'.format(years)) for year in range(1,years+1): monthsPerYear=int(12) for month in range(1,monthsPerYear+1): monthlyRainfallInches=input('How many inches of rain fell in month {}:'.format(month)) totalRainfallInches=totalRainfallInches + monthlyRainfallInches # Indicate output totalMonths=years*monthsPerYear averageRainfall=totalRainfallInches / totalMonths print('The total rainfall over {} months was {} inches and the average rainfall per month was {}.'.format(totalMonths, totalRainfallInches, averageRainfall)) # End module
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