Computer Science
Write Python programs to sum the given sequences:
2/9 - 5/13 + 8/17 …… (print 7 terms)
Python
Python Control Flow
31 Likes
Answer
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
Answered By
11 Likes
Related Questions
Write a complete Python program to do the following :
(i) read an integer X.
(ii) determine the number of digits n in X.
(iii) form an integer Y that has the number of digits n at ten's place and the most significant digit of X at one's place.
(iv) Output Y.
(For example, if X is equal to 2134, then Y should be 42 as there are 4 digits and the most significant number is 2).
Write Python programs to sum the given sequences:
12 + 32 + 52 + ….. + n2 (Input n)
Write a Python program to print every integer between 1 and n divisible by m. Also report whether the number that is divisible by m is even or odd.
Write a Python program to sum the sequence:
1 + 1/1! + 1/2! + 1/3! + ….. + 1/n! (Input n)