Creating an incremental List
<p>When I try to create an incremental list from <code>a</code> to <code>b</code> ( so something like [1,1.1,1.2,1.3,...,2] (a=1, b=2), then I start having a problem with the specific code I came up with:</p>

<pre><code>def Range(a,b,r):
    lst1=[]
    y=a
    while y&lt;b:
        lst1.append(round(float(y+10**-r),r))
        y+=10**-r
    return lst1

print Range(1,2,3)
</code></pre>

<p>Here, <code>r</code> is the power of my increments <code>(10**-r)</code>. For <code>r=1</code> or <code>r=2</code> the code works fine and ends at [...,2.0]. But for <code>r=3</code> or <code>r=4</code> it ends at [...,2.001] and [...,2.0001] respectively. But then, for <code>r=5</code> and <code>r=6</code> it goes back to ending at 2. Is there something wrong with my code or is this some sort of bug?</p>

<blockquote>
  <p>say, to get a element of 2.001, the lost has to take in y=2.000</p>
</blockquote>

<p>That's not true; it's possible that y becomes, say, 1.99999999999997.</p>

<p>You check on <code>y &lt; b</code>, but then add <code>round(float(y+10**-r),r)</code> to the list. It's of course possible that the first is true, but the second is still larger than b.</p>

<p>To see what's happening, remove the rounding, and look at the next-to-last number in your lists in the cases where it's going "wrong".</p>

python list increment