Am 04.07.2017 um 04:40 schrieb Rafael Skovron:
Hi as a challenge I have got to sum a series i / (i+1). My code isn't
summing right. Any ideas why?


def main():
     print("{0:15s}{1:20s}".format("i","m(i)"))
     for i in range(1,20):
         print("{0:<15d}{1:<20.4f}".format(i,m(i)))

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

Python 2 or Python 3? What sums do you get and what sums do you expect?

BTW in your function m(i) it's very confusing that you use the name i both for the range limit and for the loop variable. It seems to be syntactically correct, but it's certainly not readable.

HTH
Sibylle

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to