"""====================================================================== Program: Average Rainfall Calculator Author: Chris Brockamp Date: April 16, 2015 Dev Env: Python Fiddle Description: Calculates and displays the average rainfall per month using nested loops. ======================================================================""" # declare constant MONTHS = 12 # declarce variables monthly_rainfall = [] years = input("How many years of rainfall data do you want to input? ") print(years) # define nested loop to gather rainfall data for time in range(1, years + 1): for month in range(1, 13): rain = float(input("Enter total inches of rain for month {}: ".format(month))) monthly_rainfall.append(rain) print(rain) total_months = years * MONTHS # calculate and print results print("Total months of rainfall: " + str(total_months)) print("Total inches of rainfall: " + str(sum(monthly_rainfall))) print("Average inches of rainfall per month: " + str(sum(monthly_rainfall) / total_months))
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