Python - Turtle
Objectives
- Student will be able to demonstrate how flow controls, variables, and proper syntax is used to create a computer program.
- Student will demonstrate how to correctly compile and run a program.
- Student will edit and debug program source code in the text editor.
State Standards/Objectives
Computer Programming IA
- 110201-0104 Demonstrate the ability to use the editor to enter programs.
- 110201-0105 Demonstrate the ability to compile, debug and execute programs.
- 10201-0301 Demonstrate the ability to use basic elements of a specific language.
Materials
Computers available to each student with Python Interpreter, SPE, and the Turtle Python Module. Bookmark in Del.icio.us with all the python and python turtle links in the "Links" section below.
Audience
Students in this class are in grades 10-12 and are just being introduced to programming concepts.
TimeFrame
This lesson should be completed in one class period.
Procedure
Introduction: The students have a basic understanding of what programming is and have written very basic programs. However, this will be a more advanced topic and will challenge their knowledge.
Activity: The instructor will demonstrate what a python program looks like using the sample code included at the end of this lesson. The students will observe how to edit, compile and run a simple python program using the Turtle module.
After a short time for questions, student will return to their individual workstations to work on the assignment which will be to solve several problems outlined in the Assignment section below. As the students solve each problem, they should raise their hands to have their work checked by either the instructor or one of the classroom aids.
The students will use the Del.icio.us page located at http://delicious.com/kajigga/python to find information about how to solve each problem. As the instructor finds new web resources, they will be added this page for students to use.
Links
Code Sample
1 # the turtle module provides turtle graphics primitives, it uses a Tkinter canvas
2 # turtle is part of the Tkinter library (lib-tk)
3 # tested with Python24 vegaseat 30jun2005
4
5 from turtle import *
6 import time
7
8 # pen/turtle starts at the center (x=0, y=0) of the turtle display area
9
10 color("green")
11 # pen up, don't draw
12 up()
13 # centers the circle
14 goto(0,-50)
15 # pen down, draw
16 down()
17 # radius=50 center is 50 radius units above the turtle
18 circle(50)
19 up()
20 # center the turtle again
21 goto(0,0)
22 down()
23
24 # draw blue 100x100 squares
25 color("blue")
26 for deg in range(0, 61, 6):
27 right(90 + deg)
28 forward(100)
29 right(90)
30 forward(100)
31 right(90)
32 forward(100)
33 right(90)
34 forward(100)
35
36 up()
37 goto(-150,-120)
38 color("red")
39 write("Done!")
40
41 time.sleep(5) # wait 5 seconds
Assignment Problems
- Draw a square with the turtle.
- Draw a cross (Red Cross Type) on the screen
- Write your initials
- Draw horizontal lines every 20 pixels.
- Draw vertical lines every 20 pixels.
Technology Involved
While I've seen the Turtle module before, I have never actually used it in a lesson before. It appears to be a fairly effective method of teaching programming basics and allowing students to directly witness what their code is doing. I looked at using other programming learning tools such as Lego robots and Alice but these tools seem to childish for the students I deal with. Another technology tool used in this lesson for the first time is Del.icio.us. I've used it for my own bookmarking for years, but this is the first time I've used it in a lesson.