My Best Computer Science Lesson

Image by Petful

A simple Python activity to change even the most skeptical students into coding enthusiasts!

I am not prone to strong statements, however in my classroom I have come to see one lesson stand above all others for a certain type of learner. Coding can be off putting for some, and it can be hard to sway students who are content being end-users of technology. Others see themselves as less than capable with technology, and many coding challenges can end up reinforcing this belief. However, I have found that this simple Python lesson on iterations and turtle graphics can transform even the most skeptical student into believers.

Originally developed by Seymour Papert, Cynthia Solomon, and Wally Feurzeig in 1969, the turtle was a turtle-shaped mechanical robot that roamed about the floor drawing shapes with an attached pen. The user programmed the turtle using a language called LOGO, one of the first languages built specifically for teaching technology. As a homage, many modern languages today, like Java and Python, have classes and libraries that allow users to draw graphics with the turtle.

I have been using the turtle as a part of my Python unit to teach about basic programming fundamentals like variables, looping, and functions. After a brief introduction on importing libraries in Python and how to use the turtle’s functions, the lesson asks the programmer to move the turtle forward 100 pixels and turn right. The code to complete this is rather simple:

from turtle import *
Turtle = new turtle()

Even very hesitant and new learners can accomplish this task easily. So far the lesson is very accessible, but it is also still sort of bland. That skeptical student most likely will still be skeptical. The next challenge for the programmer is to make a square using a for loop – another accessible challenge. Once students learn the syntax of the for loop and how indentation works in Python, the task is fairly easy:

from turtle import *
Turtle = new turtle()
for count in range(0,4):

After this, I prompt the students with their first real challenge – how can we change the code in this loop to not draw a square, but a decreasing spiral. At this point, brows can get furrowed or agile programmers can get determined. They are going to have to work to complete this one. Very often I assist by prompting them. As they work I ask, “What happens to the length of the sides in a spiral?,” and “What variable in a loop is getting larger each time the loop iterates?” At this point, some of the students figure out that increasing the range of the loop and moving the turtle forward 100-count is the solution they are looking for.

The first “whoas” begin to come from different parts of the room as the students see Moire patterns (interference patterns) visible when the turtle makes a spiral. However, the real magic comes next. I point out to them that a spiral is a simple repeating pattern and changing the angle in the loop can have some interesting effects. I tell them that 71 and 137 are some of my favorite angles. This is usually where the classroom really explodes with excitement. All around the room, students are testing out different angles and seeing unique repeating patterns spill across the screen. Students even get possessive over the spiraling shapes they create, covering their code with their hands.

From here as we move on to cover color and randomization, the class has a different feel. Students have forgotten, even for a class period, about their struggles and have engaged with technology in a playful, childlike way. As they file out of the class, many of them smiling or talking about their creations, again I am reminded about that important lesson for educators – that play really is a powerful teacher.

Note: Try this code on the website (select Python with Turtle) if your computer doesn’t have Python. You may have to use examples and tweak code.

Learn More

Turtle Graphics

Introducing Turtle Graphics for Python

Turtle Graphics for tk Docs (used by


  • Tim McGuigan

    Tim McGuigan teaches middle school Computer Science and Robotics and is the Farrell Chair for Innovation at Shady Side Academy.

Also In The August 2018 Issue

Use SketchUp to recreate the famous optical illusion that grows and shrinks people around the room.

Learn what makes a good rogue-like game and how to make one yourself.

Unleash your inner digital chef through this simple (but mouth-watering) Python activity.

Dinosaur fossils, STEM podcasts, and a day in the life of a paleontologist.

A fun introduction to programming games with fantasy computers. The 70s and 80s are back in style!

Real life treasure hunts are a way to get outdoors, learn map skills, and have fun finding hidden caches near you.

Tips & trips to help you have a great time on the Internet, even when others don’t behave well.

How scientists finally cracked the code behind the mysterious language of Ancient Egypt.

Two small projects introducing you to Edublocks, a language that bridges the gap between Scratch and Python.

Take your CLI skills to the next level as you combine, redirect, and script commands.

It looks like JavaScript, has a Python aesthetic, and integrates easily with C/C++. Meet Lua: a scripting language for fantasy computers.

How the high-tech LIGO made a huge discovery and won its three founders a Nobel Prize.

An introduction to the devices that’ll make your robots zoom, skitter, and spin.

Learn the secrets behind pixels, image blurs, and all your favourite Instagram filters!

Links from the bottom of all the August 2018 articles, collected in one place for you to print, share, or bookmark.

Interesting stories about computer science, software programming, and technology for August 2018.

Interested but not ready to subscribe? Sign-up for our free monthly email newsletter with curated site content and a new issue email announcement that we send every two months.

No, thanks!