#get the number of years for this calculation years=input("enter years") years=int(years) #declare variable for later use annualRainfall=0 totalRainfall=0 print #run loop once for each year depending on user input for time in range(1,years+1): #run embeded loop for each month of each year for counter in range(1,13): #get monthly rainfall data monthlyRainfall=input("enter monthly rainfall in inches for year {}, month {}".format(time,counter)) monthlyRainfall=float(monthlyRainfall) #calculate total rainfall and keep a running tab totalRainfall=totalRainfall+monthlyRainfall print(totalRainfall) #calculate total months of data totalMonths=years*12 print("The total number of months included in this data is {}".format(totalMonths)) print("The total rainfall in inches is {}".format(totalRainfall)) #calculate average rainfall averageRainfall=totalRainfall/totalMonths print("The avergage rainfall per month during this period was {}".format(averageRainfall))
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