Finding a sum of series in Python 2.7.x
<p>Here's the equation </p>

<pre><code>x + x^2/2 + x^3/3 +.... x^n/n
</code></pre>

<p>How will I find the sum of this series? x is a constant term to be entered by user and n which is power is also based on user! </p>

<p>I made this program but it's not working properly.. Have a look - </p>

<pre><code>n=input("Enter power ")
x=input("Enter value of x")
i=0
while i&lt;n:
    c=n-1
    res=(x**(n-c))/(n-(c))
    print res
    i=i+1
</code></pre>

<p>So how do we make it? Thanks a ton for your help!</p>

<p>Update : The answers helped me and now the program is working as it should! This was my first time using Stackoverflow! Thanks to everyone for this.</p>

<p>Issue with your program is that your are not adding the sum. See: <code>res=(x**(n-c))/(n-(c))</code>. Instead do:</p>

<pre><code>res += (x**(n-c))/(n-(c))
</code></pre>

<p>You may also achieve it by using in-built <code>sum</code>, <code>map</code> and <code>lambda</code> functions as:</p>

<pre><code>y = 5  # or any of your number
sum(map(lambda x: (y**x)/float(x), xrange(1, y)))
</code></pre>

python