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

>>>

6 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. second code is wrong pls check
    the step up value should be 2

    ReplyDelete
    Replies
    1. Thanks for giving suggestion to correct our mistake.

      Delete
  2. You 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!

    ReplyDelete
  3. shoudn't the range be7 in first case as it goes upto n-1

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post