Cant get inner loops to add up properly
<p>My issue is with my user input totals for rainfall not adding up properly</p>

<p>my assumption is that it is not adding the 1st month in when asked on multiple years as </p>

<p><img src="http://i.stack.imgur.com/XKqhg.jpg" alt="problem explained"></p>

<pre><code>def main():

    #define accumulators
    monthRain = 0
    year = 0
    monthTotal = 0
    months = 0
    total = 0 

    #get # of years
    year = int(input("Enter the number of years to collect data for: "))

    #define month total befor it is changed below with year + 1
    monthTotal = year * 12

    #define how many months per year
    months = 12

    #Find average rainfall per month
    for year in range(year):
        #accumulator for rain per month
        total = 0
        #get rainfall per month
        print('\nNext you will enter 12 months of rainfall data for year', year + 1)
        for month in range(months):
            print("Enter the rainfall for month", month + 1, end=" ")
            monthRain = float(input(': '))

            #add monthly raingfall to accumulator
            total += monthRain
            average = total / monthTotal

    #total months of data 
    print('\nYou have entered data for', monthTotal,'months')

    #total rainfall
    print('\nThe total rainfall for the collected months is:', total)
    print('The average monthly rainfall for the collected months is:', format(average, '.2f' ))

main()
</code></pre>

<p>I think you shouldn't be resetting the <code>total</code> for each year. That's why you were missing a year's worth of data. The total rainfall in the example you provided was <code>131</code> and the average is approximately <code>5.46</code>. I ran your example and got the following.</p>

<pre><code>Enter the number of years to collect data for: 2
('\nNext you will enter 12 months of rainfall data for year', 1)
Enter the rainfall for month 1  
: 3
Enter the rainfall for month 2  
: 4
Enter the rainfall for month 3  
: 6
Enter the rainfall for month 4  
: 7
Enter the rainfall for month 5  
: 9
Enter the rainfall for month 6  
: 8
Enter the rainfall for month 7  
: 5
Enter the rainfall for month 8  
: 3
Enter the rainfall for month 9  
: 4
Enter the rainfall for month 10  
: 1
Enter the rainfall for month 11  
: 8
Enter the rainfall for month 12  
: 9
('\nNext you will enter 12 months of rainfall data for year', 2)
Enter the rainfall for month 1  
: 3
Enter the rainfall for month 2  
: 6
Enter the rainfall for month 3  
: 7
Enter the rainfall for month 4  
: 3
Enter the rainfall for month 5  
: 4
Enter the rainfall for month 6  
: 1
Enter the rainfall for month 7  
: 9
Enter the rainfall for month 8  
: 7
Enter the rainfall for month 9  
: 8
Enter the rainfall for month 10  
: 4
Enter the rainfall for month 11  
: 5
Enter the rainfall for month 12  
: 7
('\nYou have entered data for', 24, 'months')
('\nThe total rainfall for the collected months is:', 131.0)
('The average monthly rainfall for the collected months is:', '5.46')
</code></pre>

<p>Here is the corrected code: </p>

<pre><code>#define accumulators
monthRain = 0
year = 0
monthTotal = 0
months = 0
total = 0 

#get # of years
year = int(input("Enter the number of years to collect data for: "))

#define month total befor it is changed below with year + 1
monthTotal = year * 12

#define how many months per year
months = 12

#Find average rainfall per month
for year in range(year):
    #accumulator for rain per month
    #get rainfall per month
    print('\nNext you will enter 12 months of rainfall data for year', year + 1)
    for month in range(months):
        print ("Enter the rainfall for month", month + 1, " ")
        monthRain = float(input(': '))

        #add monthly raingfall to accumulator
        total += monthRain
        average = total / monthTotal

#total months of data 
print('\nYou have entered data for', monthTotal,'months')

#total rainfall
print('\nThe total rainfall for the collected months is:', total)
print('The average monthly rainfall for the collected months is:', format(average, '.2f' ))
</code></pre>

python loops nested