Preview lessons, content and tests

Computer Science & Programming solved. All in one platform.

1. To trial the platform and take tests, please take a few seconds to SIGN UP and SET UP FREE.

2. Searching for something specific? See our text overview of all tests. Scroll right for levels, and lists.

3. Student and Teacher User Guides |  Schemes of Work |   Real Teacher use Videos |


Join 36000+ teachers and students using TTIO.

Repeating with Loops and Lists

In order to draw a square, we need to do the same thing four times — we need to repeat the instruction to move the turtle forward some distance and turn 90 degrees. The for statement will repeat the forward and left four times, one time for each value in the list.

Code to try yourself (in the trinket below)

import turtle            
wn = turtle.Screen()
alex = turtle.Turtle()

for i in [0, 1, 2, 3]:      # repeat four times
    alex.forward(50)
    alex.left(90)

wn.exitonclick()

Trinket

Additional Video

www.teachyourselfpython.com