Q. Write python program to sum the given sequences :
(a). 2/9 – 5/13 + 8/17………(print 7 th term )
(b): 12 + 3 2 + 52+…….+n2 (input n)
You can understand by Watching video :-
Answer :-
(a).
a = 2
b = 9
sum = 2/9
for i in range(6):
a = a + 3
b = b + 4
if i % 2 == 0 :
sum = sum - a/b
else :
sum = sum + a / b
print("sum of sequence = ", sum)
(b).
n = int(input("enter the n term = "))
sum = 0
for i in range(1,n*2, 2):
sum = sum + (i ** 2)
print("sum of sequence = ", sum )
Output :-
(a).
Sum of sequence = 0.3642392586003134
>>>
(b).
Enter the n term = 5
Sum of sequence = 165
>>>
Enter the n term = 49
Sum of sequence = 156849
>>>
second code is wrong pls check
ReplyDeletethe step up value should be 2
Thanks for giving suggestion to correct our mistake.
DeleteYou guys make videos, share the solutions, share the questions...you do sooo much!! I am so thankful to you. Just wanted to let you know that I and many other students really appreciate your efforts. Thanks!
ReplyDeleteMost welcome 😊😊😊😊😊
Deleteshoudn't the range be7 in first case as it goes upto n-1
ReplyDeletePlease watch the video.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )