list=[1,2,3,4,5,6,7,8,9]For every third number of my list, how to add 3 to it and print | Sololearn: Learn to code for FREE!

+2

list=[1,2,3,4,5,6,7,8,9]For every third number of my list, how to add 3 to it and print

10/17/2021 2:55:14 PM

G-5256

10 Answers

New Answer

+3

yeah I put dange and then get out successfully Thanks again!!! ๐Ÿ’œ๐Ÿ’œ

+6

myList = [1,2,3,4,5,6,7,8,9] for i in range(2,9,3): myList[i] += 3 print(myList)

+3

In a loop over each third item index

+2

insert() maybe what you are looking for...

+2

myList = [1,2,3,4,5,6,7,8,9] for i in range(9): if (i+1)%3==0: myList[i] += 3 print(myList)

+1

Yor r absolutely right but i don't want to insert 3 Iist, increment 3rd index by 3 i.e if I have 4 on index 3 so i want ans as 4+3

+1

thank u โค

0

l=[1,2,3,4,5,6,7,8,9] for i in l[::3]: l[i]=l[i]+3 print(l)

0

Thanks๐Ÿ™‚

-2