title: python program to add all values from each line
body: <p>im writing a python function to do the following, add numbers from each line, so i can then find the average. this is what my file looks like:</p>
  
  <pre><code> -2.7858521
   -2.8549764
   -2.8881847
    2.897689
    1.6789098
   -0.07865
    1.23589
    2.532461
    0.067825
   -3.0373958
  </code></pre>
  
  <p>Basically ive written a program that does a for loop for each line, incrementing the counter of lines and setting each line to a float value.</p>
  
  <pre><code>   counterTot = 0      
     with open('predictions2.txt', 'r') as infile:
              for line in infile:
                  counterTot += 1
                  i = float(line.strip())
  </code></pre>
  
  <p>now is the part i get a lil stuck</p>
  
  <pre><code>   totalSum = 
     mean =  totalSum / counterTot
     print(mean)
  </code></pre>
  
  <p>As you can tell im new to python, but i find it very handy for text analysis work, so im getting into it.</p>
  
  <p><strong>Extra function</strong></p>
  
  <p>I was also looking into an extra feature. but should be a seperate function as above.</p>
  
  <pre><code>  counterTot = 0      
     with open('predictions2.txt', 'r') as infile:
              for line in infile:
                  counterTot += 1
                  i = float(line.strip())
                                      if i &gt; 3:
                                          i = 3
                                      elif i &lt; -3:
                                          i = -3
  </code></pre>
  
  <p>As you can see from the code, the function decides if a number is bigger than 3, if so, then make it 3. If number is smaller than -3, make it -3. But im trying to output this to a new file, so that it keeps its structure in tact. For both situations i would like to keep the decimal places. I can always round the output numbers myself, i just need the numbers intact.</p>