[Tutor] Not returning out the series

Alan Gauld alan.gauld at yahoo.co.uk
Tue Jul 4 04:32:44 EDT 2017

On 04/07/17 03:40, Rafael Skovron wrote:

> def m(i):
>     total = 0
>     for i in range(1,i+1,1):
>         total+=(i/(i+1))
>     return total

convert the numerator to a float. Otherwise you
are using integer division. (I'm guessing you
are running Python 2.7?)

You could also import division from future:

from __future__ import division

Alternatively you could try running Python v3.

PS, Its probably not a great idea to use i as both
the iteration variable and the input parameter.
It easily causes confusion.

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list