title: python list index out of bound
body: <p>Hello this is my first time here!</p>
  
  <p>as a assignment i got this: Now make a new function cumulative_sum that returns a new list where the i-th element is the sum of the first i+1 elements from the original list. For example, the cumulative sum of [4, 3, 6] is [4, 7, 13].</p>
  
  <p>so i have written this code:</p>
  
  <pre><code>list_1 = [4, 6, 3]
  
  def cumulative_sum(a_list):
      list_2 = []
      list_2.append(a_list[0])
      x = 1
      y = 0
          for i in a_list:
              if len(a_list) == x:
                 break
              else:
                  var1 = list_2[x]
                  var2 = a_list[y]
                  var3 = var1 + var2
                  list_2.append(var3)
                  x +=1
                  y +=1
                  return list_2
  print cumulative_sum(list_1)
  </code></pre>
  
  <p>however i keep getting a index out of bound error even though  I have a bound check like:</p>
  
  <pre><code>        if len(a_list) == x:
          break
  </code></pre>
  
  <p>excuse my english! and any other tips on my code are welcome </p>
  
  <p>this is the traceback: </p>
  
  <pre><code> IndexError                                Traceback (most recent call last)
   /Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
  202             else:
  203                 filename = fname
  --&gt; 204             __builtin__.execfile(filename, *where)
  
  /Users/arkin/programming/multadd.py in &lt;module&gt;()
   97             return list_2
   98 
  ---&gt; 99 print cumulative_sum(list_1)
  100 
  101 
  
  /Users/arkin/programming/multadd.py in cumulative_sum(a_list)
   89             break
   90         else:
  ---&gt; 91             var1 = list_2[x]
   92             var2 = a_list[y]
   93             var3 = var1 + var2
  </code></pre>