title: python zero division error. float division by zero. simple script
body: <p>I am trying to convert an array into a percent change array. it is simple, but I do not know why I am getting a zero division error. I tried putting </p>
  
  <pre><code>from __future__ import division
  </code></pre>
  
  <p>at the top of my file, but no dice. </p>
  
  <p>my code:</p>
  
  <pre><code>def convert(anarr):
       x = 1
      while(x &lt; len(anarr)):
          anarr[x] = (anarr[1] - anarr[x])/anarr[1]
          x += 1
      print anarr
  </code></pre>
  
  <p>main:</p>
  
  <pre><code>&gt;&gt;&gt;
  &gt;&gt;&gt;
  &gt;&gt;&gt; myarr = [20130101.0,34.75,34.66,34.6,34.6,34.61,34.65,34.69]
  &gt;&gt;&gt; convert(myarr)
  &gt;&gt;&gt; Traceback (most recent call last):
    File "&lt;pyshell#10&gt;", line 1, in &lt;module&gt;
      convert(myarr)
    File "C:\Users\viral\Desktop\python\mapping.py", line 38, in convert
      anarr[x] = (anarr[1] - anarr[x])/anarr[1]
  ZeroDivisionError: float division by zero
  </code></pre>