title: Get sum of numbers using a Function and For Loop
body: <p>I want to define a function, <code>sumAll(n)</code> that <code>sums all numbers from 1 to n</code>.</p>
  
  <p>For example, when I call <code>sumAll(10)</code> should return the <code>answer 55</code>...</p>
  
  <p>Because:</p>
  
  <pre><code>1+2+3+4+5+6+7+8+9+10 = 55
  </code></pre>
  
  <p>The function <code>sumAll</code> needs to use a for loop to carry out this summation, and it will have to use a sum variable that increases in value over each iteration of the for loop.</p>
  
  <p>I have a working function that does not use a for loop, but I need to know how to use a for loop to accomplish this as well.</p>
  
  <p>Here is the working program:</p>
  
  <pre><code>def sumAll(n):
      if n == 0:
          return 0
  
      return n + sumAll(n - 1)
  
  number = int(raw_input("Please enter a number: \n"))
  
  print ("The answer is: ") + str(sumAll(number))
  </code></pre>
  
  <p>How do I use a "for" loop to accomplish this?
  Am I right in assuming the <code>"for loop"</code> should be nested in the <code>"sumAll"</code> function?</p>
  
  <p>I have tried many times to do this using a for loop and I keep getting a <code>infinite result and errors</code>...</p>
  
  <p>Here is my code:</p>
  
  <pre><code>def sumAll(n):
      y = n + sumAll(n -1)
      return y
  
  num = int(raw_input("Please enter a number")
  for n in range(num):
      num = sumAll(num)
      print num
  </code></pre>