Can you change the color of the turtle pen in a while loop using a list?
Question: I want to know if you could change the color of the python turtle pen when a
while loop iterates and continue to change everytime the while loop iterates.
So far I have this but want to make it change color too.

    
    
    from turtle import *
    
    w = 10
    # Number of steps to take
    x = 40
    # Number of sides to make
    y = 2
    # Size of turtle pen
    z = x
    # Same variable as x but not manipulated
    speed ('fastest')
    # Speed of pen 
    
        for i in range(10):
            while x > 0:
                pensize (y)
                forward (w)
                left (360/z)
                x = x-1
                y = y+1
            while x < z:
                pensize (y)
                forward (w)
                right (360/z)
                x = x+1
                y = y-1
            print (i)
    

Any suggestions?


Answer: There is a `pencolor` function, so, yes, you can change the color.

If your problem is not turtle, but taking the values elegantly out of a too
short list, I suggest `itertools`, and the `next()` method.

    
    
    from itertools import cycle
    color_sequence = cycle([4,5,6])
    for i in range(10): print color_sequence.next()
    

And if you don't want to to have an extra command for every stroke, you just
replace the call to `forward()` by a call to your own
`list_colored_forward()`.

