Python Programming to generate a series and sum the numbers of series. In the program an input value of x and power n will be given. On the basis of input the python program will print the series along with its addition.
Python programming series and sum -How it works
Here we are working on series that print the input number first time i.e x and after that goes on printing x power n. n is a natural number starting from 1 to n. like for x=2, y=4 series will be 2 4 8 16 and sum is the sum of all its element n series 2+4+8+16=30.
Let’s write a python program
Write a program (WAP) to input value of x and n and print the series along with its sum in Python Program using while loop.
# Here series is x,x^2,x^3,x^4……………,x^n.
#sum is sum of series elements
x=float(input(“Enter the value of x”)) #to input the start value of series
n=float(input(“Enter the value of n”))#the number of value series has to be carried to
i=1 #start value is taken as 1
s=0 #sum value is taken as 0
while i<n: #it is a loop which continues untill this condition is true
y=x**i #Here y equal to x^i
print(y, “+”, end=”) #here it is printed as series
s=s+y # here sum is calculated
print(x**n) #to print the last element of series
s=s+(x**n) #to add the last element of series
print(“Sum of series =”, s)#print function shows the output on output screen
Testing the Series and Addition program
Here is the output shown for various input value.
Here the first value as input is 6 and second value the number of turn is 5 then it present 5 terms as series and sum of all the numbers . Series is 6 36 216 1296 7776 and sum of series 9330.
Congrats, our Python Program to Print Series and Addition is working fine.
Python programming series and sum source code –Click here
For more programs – Click here