43 - Write a program in Python to input the value of x and n and print the sum of the following series:
1 + x + x2 + x3 +x4 + -------- xn
x=int(input("Enter the value of x: "))
n=int(input("Enter the value of n: "))
sum=0
for i in range(0,n+1):
sum=sum+pow(x,i)
print("Sum of the series=",sum)
Output:
Enter the value of x: 2
Enter the value of n: 3
Sum of the series= 15
Enter the value of x: 2
Enter the value of n: 4
Sum of the series= 31
No comments:
Post a Comment