Skip to content
Programming Exercises · Q6

Q.Write a program to find the sum of 1+ 1/8 + 1/27......1/n^3, where n is the number input by the user.

Yanam BieapTextbookSubjective· 3mImportance★★★★★est
90% · 35/39 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Recognise the series as the sum of reciprocals of cubes (the i-th term is 1 divided by i^3) and accumulate 1/i**3 over i = 1 … n in a running-total loop.

The idea: identify the general term. The denominators 1, 8, 27, … are 1^3, 2^3, 3^3, so the series is:

S(n) = 1/1^3 + 1/2^3 + 1/3^3 + ... + 1/n^3

Any "sum a series" task is the accumulator pattern: start a total at 0, loop the term index i from 1 to n, and add the i-th term each pass.

Program

n = int(input("Enter n: "))

total = 0.0
for i in range(1, n + 1):
    total += 1 / i**3

print("Sum of the series:", total)

Sample run

Enter n: 3
Sum of the series: 1.162037037037037

Trace for n = 3

iterm 1/i**3total after adding
11.01.0
20.1251.125
30.037037037…1.162037037037037

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.