What am I doing wrong ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What am I doing wrong ?

The function cubicSeries takes an integer n and add the sequence of numbers which are cubed from the beginning to the integer. If n is less than or equal to 0 then the function must return 0. A while loop must be used in this function. The cube of the input n MUST be inclusive in the sum https://code.sololearn.com/crrA1GJgsJg3/?ref=app

3rd Oct 2021, 5:39 PM
Triz
Triz - avatar
3 Answers
+ 1
Triz you should use a while loop. (not a "hidden" for loop 😉) def cubicSeries(n): if n <= 0: return 0 else: total = 0 while n>0: total= total + n**3 n= n-1 return total print(cubicSeries(6))
3rd Oct 2021, 5:56 PM
Coding Cat
Coding Cat - avatar
+ 1
Coding Cat Thank you!
3rd Oct 2021, 6:05 PM
Triz
Triz - avatar
+ 1
Triz you're welcome.
3rd Oct 2021, 6:08 PM
Coding Cat
Coding Cat - avatar