Adding data to a Python list
<p>I've just started playing around with python lists, I've written the simple code below expecting the printed file to display the numbers [12,14,16,18,20,22] but only 22 is displayed. Any help would be great.</p>

<pre><code>a=10
b=14
while a &lt;= 20:
    a=a+2
    b=b-1
    datapoints=[]
    datapoints.insert(0,a)
print datapoints
</code></pre>

<pre><code>a=10
b=14
datapoints=[]  # this needs to be established outside of your loop

while a &lt;= 20:
    a=a+2
    b=b-1
    datapoints.append(a)
print datapoints
</code></pre>

<p>You need to set up datapoints outside your loop, and then inside your loop, append each additional datum to datapoints</p>

python python-2.7