Python: multiplying 'for i in range(..) iteration'
<p>So I have an assignment where I am required to return <code>inf</code> by multiplying <code>x</code> by 10 multiple times using a:</p>

<pre><code>for i in range(...)
</code></pre>

<p>so the main part of my code is:</p>

<pre><code>   def g(x):
      x = 10.*x
      for i in range(308):
          return x
</code></pre>

<p>and if I enter </p>

<pre><code>    &gt;&gt;&gt; g(3.)
    &gt;&gt;&gt; 30.0
</code></pre>

<p>I expected it to iterate it 308 times to the point where I get <code>inf</code>. Is there a line I can use that uses the number in the <code>for i in range(..)</code> to iterate the equation that many times?  For example:</p>

<pre><code>   def g(x):
       x = 2.*x
       for i in range(3):
       # the mystery line I need for it to work
           return x
   &gt;&gt;&gt; g(4.)
   &gt;&gt;&gt; 16.0
</code></pre>

<p>but it doesn't give me that. Rather it returns <code>8.0</code></p>

<p>Another way I did it that actually made it work was using print. But I don't think it's valid using a print statement in an assignment asking to <code>return inf</code>. </p>

<p>I think you have the right parts, just not arranged correctly. Try something like this:</p>

<pre><code>def g(x):
      for i in range(308):
          x = 10.*x     # because we've moved this line into the loop, it gets run 308 times
      return x    # since we've unindented this line, it runs only once (after the loop ends)
</code></pre>

<p>The part you want to be repeated needs to be indented after the line with the <code>for</code> statement. Stuff you don't want repeated (like the <code>return</code>, which can only happen once), should not be in the loop.</p>

python python-3.x