1.

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

Answer» # python program to find the sum of series:\xa01 + x² + x³ + ... + xⁿn = int(input(\'Enter the value of n: \'))x = int(input(\'Enter the value of x: \'))sum_of_series = 0for i in range(n+1): sum_of_series += pow(x,i)print(\'Sum of the series is:\',\xa0sum_of_series) \tInput the value of x and n from user as integer type\tdefine 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.\twe use for loop with range of i varying from 0 to n\xa0(remember this is not for infinite series) giving the power of x from 0 to n\tevey iteration we add x^i to the sum\tfinally print the\xa0sum of series<br>x = int(input("Enter a value of x"))y = int(input("Enter a value of y(for x**n)"))sum = 0for i in range(n+1): sum+ = x**iprint("The sum total of ",n,"Terms:-" sum)


Discussion

No Comment Found