118. Python Program to Compute the 1+4+9+16+ …….+n Series.
How does this program work?
- This program is used to find the Sum of the given series 1+4+9+16+ …….+n using Python.
- The integer entered by the user is stored in variable n i.e last term for the given series.
- Declare variable sum and Initially initialize with 0.
- By using for loop we can find the sum of series for square of numbers upto nth term.
Here is the code
n = int(input("Enter a number: "))
num = 0
print("Series till the enter number: ")
for i in range(1,n+1):
i=i**2
print(i, end=" ")
num+=i
print("\nSum of the series: ",num)