def series_sum(n):
listSeries = [1, 1/4, 1/7, 1/10, 1/13, 1/16, 1/19, 1/22, 1/25]
sum = 0.00
for i in range(n):
sum += listSeries[i]
return str("{:.2f}".format(sum))
Hey guys, my code passes all tests and kind of works with this challenge, but I get one annoying error, which I don't know how to solve. List index out of range. list[i-1] didn't work out. I hope it is not necessary to rewrite the whole code to fix this.
codewars.com/kata/555eded1ad94b00403000071/train/python
Traceback (most recent call last):
File "main.py", line 13, in <module>
Test.assert_equals(series_sum(15), "1.94")
File "/home/codewarrior/solution.py", line 5, in series_sum
sum += listSeries[i]
IndexError: list index out of range
Thanks.