Issue with Sum of Odd Numbers Code
<p>I know that there are other post on this and I have referred to them but I can't seem to figure this one out.</p>

<p>This code gives me the value 2500, just 2500.</p>

<pre><code>sum = 0;
for i in range (1,100):
    if i % 2 == 1:
        sum = sum + i;
print (sum)
</code></pre>

<p>However I want the range to vary. So I came up with this</p>

<pre><code>def odd_sum_n(n):
    sum = 0;
    for i in range(1,2*n):
        if i % 2 != 0:
            sum = sum + i;
    print (sum)

print(odd_sum_n(5))
</code></pre>

<p>But this code gives me the solution</p>

<pre><code>25
None
</code></pre>

<p>I kept trying to adjusting this code but I don't see why the "None" appears. I'm new to python so any help would be appreciated!</p>

<p>you want to get the value from your <code>def odd_sum_n(n)</code> for that you need to <code>return(sum)</code> and then just <code>print(odd_sum_n(n))</code> this will only print your answer.
 you are getting <code>none</code> because you are trying to print two times one time in <code>def</code> and other time in when you calling the <code>function</code> it self. hope this helps you why you were getting <code>none</code> in your result.</p>

python