Kids Coding Lesson Using Python Turtles: Today YOU be the computer…

My first serious contact with computer code occured in the early 80’s, using a drawing program known as Logo. Our elementary school had a small computer lab, which we were allowed to use a few times per week. The premise of Logo was simple: the user controls a “Turtle”, which was moved around the screen to draw lines and fill in shapes. Kids being kids, we started off drawing the nice shapes suggested by our teachers and things quickly devolved into a contest to see who could make the turtle move fastest…

One recent Saturday morning, I introduced my children to the ideas behind Logo, using Python’s turtles library. This is a good (free!) recreation of the program I remember and, better yet, is included as part of Python’s standard library. To use it, type “import turtles” at the interpreter prompt and you’re good to go…

Incidently, this was not a hardcore programming lesson. While I dearly hope my kids will someday debate the merits of using object oriented vs functional programming, we had a simpler set of goals. With young kids, you’ve got to keep the lesson fun and tangible. There were a couple of basic programming ideas I wanted to slip in along the way:

  • Using variables to store a value
  • Using if-then statements to control the flow of a program
  • Looping / Iteration (just for loops for now)
  • The importance of good comments…

Logo is an elegant little language, in the sense that you can be semi-productive after understanding a handful of core commands. For those following along at home, here are about half-a-dozen statements that you should start with:

  • Basic Movement: forward (steps), backward (steps)
  • Basic Turning: left (degrees) / right (degrees) : turn left (right) by X degrees
  • penup() / pendown(): controls if the turtle is going to draw a line…
  • begin_fill(), end_fill(): controls if you are going to fill in an enclosed space; use begin_fill() when you begin the enclosing line and end_fill() when you’re done.

These can be packaged into procedures using variables and standard Python control statements (if statements, for statements for loops, and function definitions). For more about controlling the flow of a program, check out this section of the Python Tutorial.

The lesson itself was pretty straightforward:

  1. I turned on a computer, fired up Python, and did a quick demo of what the turtles library could do, drawing a cool shape from one of this library of examples.
  2. Having attracted their attention, we went to the dining room where I explained a couple of the basic ideas of turtle graphics and demonstrated them by having the kids hop around the dining room. One child was the turtle and the other child was the programmer….
  3. I had their full attention once they realized they could make each other hop around the room (and hop into the walls, tables, chairs, pets…)
  4. Next step….I asked my second grader to start writing commands down. She took notes as we moved around the room: forward (20), right(90)…making a square..
  5. At the end she looked up. “Ok, I’m ready to code it”…. and ran to the computer.
  6. I showed her how to open up a new script window and enter her program.
  7. She tapped the first two lines of the loop into the program and looked up: “How do you cut & paste on this thing?” (Egad! I’m raising a script kiddie!)
  8. After a quick explanation of how for-loops work, we had a working program!
  9. We made a couple of other tweaks such as filling in a color (first blue, then green) and changing the size of the shape using a variable…
  10. After showing her work to Mom, we were done!

It was a fun little experience and, better yet, she asked me to show it to her again the next weekend….

If you like this post, go ahead and share it…


Leave a Reply

Your email address will not be published. Required fields are marked *