1/2 in python shell gives 0.5 while within a program, it gives 0 : <p>Simple Question:</p>

<p>When I do 1/2 in python shell it gives float value</p>

<pre><code>&gt;&gt;&gt; 1/2
&gt;&gt;&gt; 0.5
</code></pre>

<p>But</p>

<pre><code>sum = 0
for i in range(1, 20):
    p = 1/i
    print(p)
    val = 2.0**p
    sum += val
    print(sum)
</code></pre>

<p>When  run this program, value of p always comes to 0.</p>

<p>What is the reason behind this behaviour. What am i missing?</p>
