How to use a variable to find another variable in a list - python
<p>(Python 3.x)</p>

<pre><code>z=[]
x=0
while 1==1:
    x=x+1
    y=1
    z.append(x)
    while y==1:
        a = 0
        b = 0
        if z(a)==x:
            print(x)
            y = 2
        elif x%z(a)!= 0:
            a = a+1
        elif b == 2:
            y = 2
        else:
            b = b+1
</code></pre>

<p>So, I made a code to find all the prime numbers until python crashes. However, it relies on z(a) for it to work. The idea is that as "a" changes, it moves on in the list. </p>

<p>"z(a)" is where the error lies, so does anyone know a way to fix this?</p>

<p><code>z</code> is a list. You can approach values inside it by indexes using the <code>z[a]</code> operator (and not <code>z(a)</code> which assumes a function call with <code>a</code> as parameter).</p>

<hr>

<p>I've took the liberty of using <code>boolean variables</code>, <code>+=</code> operators and unpacking values:</p>

<pre><code>z = []
x = 0
while True:
    x += 1
    y = True
    z.append(x)
    while y:
        a, b = 0, 0
        if z[a] == x:
            print(x)
            y = False
        elif x % z[a]: a += 1
        elif b == 2: y = False
        else: b += 1
</code></pre>

<hr>

<p>I believe that's what you want to achieve (infinitely incrementing prime generator):</p>

<pre><code>def prime (n): return not any([n % i == 0 for i in range(2, n)])
x = 0
while True:
    if prime(x): print(x)
    x += 1
</code></pre>

python python-3.x