Q. Write a short program to print the following series:

(i) 1 4 7 10 ………. 40

(ii) 1 -4 7 -10 ………….. -40


You can understand by Watching video :-



Answer :-

(i)

for i in range(1,41,3):
	print(i,end=" , ")

(ii)

for i in range(1,41,3):
    if i % 2 == 0 :
        print(-i,end=" , ")
    else :
        print(i,end=" , ")      

Output :-

(i)

1 , 4 , 7 , 10 , 13 , 16 , 19 , 22 , 25 , 28 , 31 , 34 , 37 , 40 ,
>>> 

(ii)

1 , -4 , 7 , -10 , 13 , -16 , 19 , -22 , 25 , -28 , 31 , -34 , 37 , -40 ,
>>>

3 Comments

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

  1. amm.. it should be '-3' right?

    ReplyDelete
    Replies
    1. the second one...

      Delete
    2. Please, Copy the program And run it.
      In second answer look line 3 , there is -i

      Delete

Post a Comment

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

Previous Post Next Post