[Edu-sig] teaching python using turtle module

John Posner jjposner at optimum.net
Tue Dec 1 21:02:57 CET 2009


Hi Brian,

If you want to start a little bit more simply, how about a program that 
draws alternating black and white squares. For the students who "get it" 
right away, challenge them to expand the program into one that draws an 
entire 8x8 checkerboard.

HTH,
John

#------------------------- python 2.6.4
from turtle import *

SIDELEN = 30
COUNT = 8

def DrawBox(count):
    """
    make turtle draw a box at current position,
    using "count" arg to determine fillcolor
    """
    # determine color
    if count % 2 == 1:
        fillcolor('black')
    else:
        fillcolor('white')
    
    # draw box
    begin_fill()
    for i in range(4):
        forward(SIDELEN)
        left(90)
    end_fill()

######## main program

# draw row of boxes
for i in range(COUNT):
    DrawBox(i)
    forward(SIDELEN)

junk = raw_input("Press Enter ...")
#-------------------------



More information about the Edu-sig mailing list