generating pi in python
<p>I would like to know how to adapt this code to give me X digits of pi when asked
because right now it just prints a random amount</p>

<pre><code>while True:
    print("how many digits of pi would you like")


    def make_pi():
        q, r, t, k, m, x = 1, 0, 1, 1, 3, 3
        number = int(input())
        for j in range(int(number)):
            if 4 * q + r - t &lt; m * t:
                yield m
                q, r, t, k, m, x = 10 * q, 10 * (r - m * t), t, k, (10 * (3 * q + r)) // t - 10 * m, x
            else:
                q, r, t, k, m, x = q * k, (2 * q + r) * x, t * x, k + 1, (q * (7 * k + 2) + r * x) // (t * x), x + 2


    digits = make_pi()
    pi_list = []
    my_array = []

    for i in make_pi():
        my_array.append(str(i))

    my_array = my_array[:1] + ['.'] + my_array[1:]
    big_string = "".join(my_array)
    print("here is the string:\n %s" % big_string)
</code></pre>

<pre><code>print('{:.xf}'.format(math.pi))
</code></pre>

<p>Where <code>x</code> is the number of digits of pi you want to print after the decimal.</p>

<p>EDIT:</p>

<p>IF you want to do it you way then</p>

<pre><code>big_string = ''.join(my_array[:x])
</code></pre>

<p>Where x is the number of <em>characters</em> including leading 3 and decimal point.</p>

python python-3.x pi