121. Python Program to Compute the 1+4+8+11+ …….+n Series.
How does this program work?
- This program is used to find the Sum of the given series 1+4+8+11+ …….+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, And also Declare another variable fact initialize with 1.
- First we need to calculate the factorial of number after that perormaed by sum for n terms.
Here is the code
n = int(input("Enter a number: "))
num = 1
a = 0
print("Series till the enter number: ")
for i in range(num,n+1):
if(i==1):
num = 1
elif(i%2 == 0):
num=num+3
else:
num=num+4
print(num,end=" ")
a+=num
print("\nSum of the series: ",a)