CBSE Class 11 Computer Science Question 148 of 161

Flow of Control — Question 25

Back to all questions
25
Question

Question 23b

Write programs to find the sum of the following series:

x + x2/2 + x3/3 + ...... + xn/n (Input x and n both)

Solution
x = int(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))

sum = 0

for i in range(1, n + 1) :
    term = x ** i / i
    sum += term

print("Sum =", sum)
Output
Enter the value of x: 2
Enter the value of n: 5
Sum = 17.066666666666666
Answer