CBSE Class 11 Computer Science
Question 143 of 161
Flow of Control — Question 20
Back to all questions 20
Question Question 20a
Write Python programs to sum the given sequences:
2/9 - 5/13 + 8/17 ...... (print 7 terms)
Solution
n = 2 #numerator initial value
d = 9 #denominator initial value
m = 1 #to add/subtract alternate terms
sum = 0
for i in range(7) :
t = n / d
sum += t * m
n += 3
d += 4
m *= -1
print("Sum =", sum)Output
Sum = 0.3642392586003134