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 ,
>>>
amm.. it should be '-3' right?
ReplyDeletethe second one...
DeletePlease, Copy the program And run it.
DeleteIn second answer look line 3 , there is -i
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )