Computer Science, asked by kumarnirmal447, 2 months ago

write a Python program to input the value of x and n
and point the sum :

1+x+x²+x³........+x^n​

Answers

Answered by prabhas24480
3

# python program to find the sum of series: 1 + x² + x³ + ... + xⁿ

n = int(input('Enter the value of n: '))

x = int(input('Enter the value of x: '))

sum_of_series = 0

for i in range(n+1):

   sum_of_series += pow(x,i)

print('Sum of the series is:', sum_of_series)  

Input the value of x and n from user as integer type

define a variable with value of zero to add up till the sum of series, this must be outside the loop, else each time the loop repeats value will set to zero defeating the purpose.

we use for loop with range of i varying from 0 to n (remember this is not for infinite series)  giving the power of x from 0 to n

evey iteration we add x^i to the sum

finally print the sum of series

Similar questions