Teach Your Kids to Code by Using the Turtle Library

draw a house

Example 1: Draw a square

from turtle import *home()
speed(1)
goto(-100,-100)for i in range(4):
forward(200)
left(90)
turtle.done()

Example 2: Draw a rainbow

import turtle
import colorsys
turtle.speed(0)
turtle.hideturtle()
turtle.bgcolor('light blue')
turtle.title('49-Color Rainbow')
turtle.setup(700,700)
num_colors = 49
radius = 300
penwidth = 20*7/num_colors
hue = 0
for i in range(num_colors):
(r,g,b) = colorsys.hsv_to_rgb(hue,1,1)
draw_one_color_arc(0,-100,radius,penwidth,(r,g,b))
radius -= (penwidth-1) #overlapping a little removes the gaps
hue += 0.9/num_colors

Example 3: Draw a house

Example 4: Draw a Sudoku board

Basic Moving Commands

Tell Turtle’s State Commands

Pen Control Commands

{
'shown': true,
'pendown': true,
'pencolor': 'black',
'fillcolor': 'black',
'pensize': 3,
'speed': 3,
'resizemode':
'noresize',
'stretchfactor': (1.0, 1.0),
'shearfactor': 0.0,
'outline': 1, 'tilt': 0.0
}

Initial Turtle State

Developer in China, AI and machine learning enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store