 <p><code>b</code> is not definied in your while (as <code>a</code>). In fact <code>a</code> and <code>b</code> are only define in the <code>F(n)</code> function and they are local variables.</p> <p>You should read some documentation about Programming and python first. But the following code should works:</p> <p>(I suppose that you want <code>while a/b &lt;= 536</code> as this is not clear in your question)</p> <pre><code>def F(n): a, b = 0, 1 for i in range(0, n): a, b = b, a+b return a, b for c in range(0, 70): a,b = F(c) print(a) while a/b &lt;= 536: print('Ratio:{}/{}'.format(b,a)) a, b = F(a) </code></pre> <p>An other solution is to totaly rewrite your code:</p> <pre><code>def F(a, b): c = a + b return c,a a, b = 0, 1 for c in range (0,70): a, b = F(a,b) print (a) while a/b &lt;=536: print(a/b) a,b = F(a, b) </code></pre>