Having output issues with python; loop totals and averages
<p>Having a few output issues with my nested loop, normally I use <code>break</code> to add some lines into my code or <code>print()</code></p>

<p>When I use <code>print()</code> within my code my output looks like I am typing totals on a new line all together that is not what I want</p>

<p>Following is a picture of my current output and where I need a blank line;</p>

<p><a href="http://i.stack.imgur.com/q77bU.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/q77bU.jpg" alt="enter image description here"></a></p>

<p>Second thing:</p>

<p>My code is not calculating the information correctly to find the total and average rainfall per month.</p>

<p>code follows</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: "))

#blank line
print()

#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('Next 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('You have entered data for', monthTotal,'months')

#blank line
print()

#total rainfall
print('The total rainfall for the collected months is:', total)
print('The average monthly rainfall for the collected months is:', average)


main()
</code></pre>

<blockquote>
  <p><em>Following is a picture of my current output and where I need a blank line</em></p>
</blockquote>

<p>In order to get a blank line before <code>You have entered data for</code>, add <code>\n</code> at the start of the string. It represents new line. Hence your print statement should be as:</p>

<pre><code>print("\nYou have entered data for")
</code></pre>

<blockquote>
  <p><em>my code is not calculating the information correctly to find the total and average rainfall per month.</em></p>
</blockquote>

<p>On dividing two <code>int</code> values, python returns <code>int</code> as by default excluding the float precision. In order to get the <code>float</code> value, conver either of numerator or denomenator to <code>float</code>. Example:</p>

<pre><code>&gt;&gt;&gt; 1/5
0  # &lt;-- Ignored float value as between two int
&gt;&gt;&gt; 1/float(5)
0.2  #&lt;-- Float value to conversion of denomenator to float
</code></pre>

<p>Also, in <code>average = total / monthTotal</code>, I believe that the <code>average</code> is need for per month basis. It should be <code>month</code> instead of <code>monthTotal</code>. Because <code>total</code> will be having the sum of rain for <code>month</code> months. In order to get average of rain in <code>month</code> months, your equation should be:</p>

<pre><code>average = total / float(month)
</code></pre>

python loops nested