No products in the cart.

Find a program to sum of …

CBSE, JEE, NEET, CUET

CBSE, JEE, NEET, CUET

Question Bank, Mock Tests, Exam Papers

NCERT Solutions, Sample Papers, Notes, Videos

Find a program to sum of a series s =1+x+(x×x)+(x×x×x)____(x)power n
  • 2 answers

Preeti Dabral 3 years, 1 month ago

# 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

Anmol Chawla 3 years, 1 month ago

x = int(input("Enter a value of x")) y = int(input("Enter a value of y(for x**n)")) sum = 0 for i in range(n+1): sum+ = x**i print("The sum total of ",n,"Terms:-" sum)
http://mycbseguide.com/examin8/

Related Questions

What is alu
  • 1 answers
Write a program for swapping two numbers
  • 1 answers
Write a program for swapping two numbers?
  • 0 answers
Define packages
  • 0 answers

myCBSEguide App

myCBSEguide

Trusted by 1 Crore+ Students

Test Generator

Test Generator

Create papers online. It's FREE.

CUET Mock Tests

CUET Mock Tests

75,000+ questions to practice only on myCBSEguide app

Download myCBSEguide App