dimanche 28 juillet 2019

How to change object once in a loop

I am trying to make it so the object X is the background and A is an object to be moved up or down, but once i use loop to change the A to X, the loop finds the a in the next line and does it once again, how do i make it so it only changes once and moves on?

newlist = ['X','X','A','X','X','X','X']

for i in range(len(newlist)):

    print(newlist[i])

    if newlist[i] == 'A':

        newlist[i] = 'X'

        newlist[i+1] = 'A'

this is what i tried,

It should show X X X A X X X from X X A X X X X

but right now it shows X X X A A A A

Aucun commentaire:

Enregistrer un commentaire