#Chapter 5 Exercise 7 by Vishal Sharma totalRainfall = 0.0 monthRainfall = 0.0 averageRainfall = 0.0 years = 0 totalMonths = 0 # Get number of years years = int(input('Enter the number of years: ')) # Get rainfall by month for year in range(years): print ('For year ', year + 1, ':') for month in range(12): monthRainfall = float(input( \ 'Enter rainfall: ')) # Add to total number of months totalMonths += 1 # Add to total rainfall amount totalRainfall += monthRainfall # Calculate the average rainfallji averageRainfall = totalRainfall / totalMonths print('For ', totalMonths, 'months') print('Total rainfall: ', format(totalRainfall, '.2f'),'inches') print('Average monthly rainfall: ',format(averageRainfall, '.2f'),'inches')
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