totalYears = int(input("How many years would you like to calculate? ")) for years in range(totalYears): total = 0.0 print("Year {}".format(years + 1)) for month in ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'): inches = float(input(month)) total += inches totalInches = total totalMonth = totalYears * 12 averageInches = total / totalMonth print("Total months: {}".format(totalMonth)) print("Total inches of rainfall in {} year(s): {} ".format(totalYears,totalInches)) print("Average amount of rainfall per month in {} year(s): {} inches".format(totalYears,averageInches))
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