Python Forum

Full Version: Question about moving a turtle
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Question about moving a turtle - multiplying index by 10 on line 15 moves the next line over 10 pixels on the x-axis, but if the first value of index in range(5) is zero, then how does 10 * 0 (which just equals zero) actually change the next line's x position? I sure I am just not understanding something. Thanks.

from turtle import *
space = Screen()
height = space.window_height()
maxY = height / 2
sue = Turtle()
sue.pensize(10)
sue.left(90)

for index in range(5):
sue.penup()
if index % 2 == 0:
    sue.color('red')
else:
    sue.color('black')
sue.goto(index * 10, -1 * maxY)
sue.pendown()
sue.forward(height)