Skip to content

Instantly share code, notes, and snippets.

@Mgregchi
Created August 3, 2025 21:10
Show Gist options
  • Select an option

  • Save Mgregchi/5b33177699cfd196b93767006e3be4c2 to your computer and use it in GitHub Desktop.

Select an option

Save Mgregchi/5b33177699cfd196b93767006e3be4c2 to your computer and use it in GitHub Desktop.
Teaching kids how to code with python by using turtle library to make leaning fun

Interactive Python


Project Structure

Let’s set up our Python adventure! Create a folder called PythonAdventures. Inside, we’ll save all our Python files (e.g., turtle_drawing.py). Use a text editor like Thonny or an online tool like Replit, and ensure Python is installed (Turtle is built-in). Ready? Let’s draw and code!


Week 1: Python Basics – Drawing with Variables and Data Types

Session 1: Meet Python and Turtle with Variables

  • Topic: Let’s draw shapes with Turtle and store values!
  • Teaching Moment:
    "Hello, class! Python is our magic coding tool, and Turtle is our drawing friend! Today, we’ll use variables—special boxes to store things like colors or sizes. Let’s draw together!"
  • Interactive Demo (turtle_start.py):
    "I’m drawing a rectangle. Which sides are longer—the top and bottom, or left and right? Raise your hands!"
    • Kids: "Top and bottom!"
    • Teacher: "Great! Let’s call the longer sides long_side and the shorter ones short_side. What numbers should we use? How about 100 for top/bottom and 50 for left/right?"
    • Kids: "Yes!"
    • Teacher: "Awesome! Where should we start drawing—left, top, right, bottom?"
    • Kids: "Top left!"
    • Teacher: "Perfect! Let’s set the starting point. What color should it be?"
    • Kids: "Blue!"
  • Sample Code (turtle_start.py):
    import turtle
    
    t = turtle.Turtle()
    t.shape("turtle")
    long_side = 100    # Top and bottom length
    short_side = 50    # Left and right length
    color = "blue"     # Our color choice
    t.color(color)
    t.penup()
    t.goto(-long_side/2, short_side/2)  # Start at top left
    t.pendown()
    t.forward(long_side)  # Top
    t.right(90)
    t.forward(short_side)  # Right
    t.right(90)
    t.forward(long_side)   # Bottom
    t.right(90)
    t.forward(short_side)  # Left
    t.right(90)
    turtle.done()
  • Explanation:
    "long_side and short_side are variables storing numbers. color holds a word (string). goto() moves Turtle without drawing, and pendown() starts drawing. Try changing color to ‘red’!"
  • Interactive Step:
    "Change long_side to 120 and short_side to 60. What shape do you get? Tell a friend!"
  • Exercise:
    "Create variables side_length (80) and my_color ("green"). Draw a square using a loop with forward(side_length) and right(90) four times."
  • Mini-Project: My Shape
    • Task: "Pick a size (e.g., 90) and my_color (e.g., "yellow"). Draw a square or triangle with Turtle. Where should it start?"
    • Outcome: "Show your shape—amazing!"

Session 2: Data Types and Creative Storage

  • Topic: Let’s explore what variables can hold!
  • Teaching Moment:
    "Nice shapes! Variables can store different things—numbers, words, or yes/no. Let’s test them. Is color a number? No, it’s a word! Let’s use a number for size instead."
  • Interactive Demo (turtle_types.py):
    "I drew a circle. Should it be big or small? Let’s use a number for size!"
    • Kids: "Big!"
    • Teacher: "Great! Let’s call it circle_size—how about 80? Is that a word or number?"
    • Kids: "Number!"
    • Teacher: "Yes! Now, what color—a word like ‘orange’?"
    • Kids: "Yes!"
    • Teacher: "Perfect! Let’s store it."
  • Sample Code (turtle_types.py):
    import turtle
    
    t = turtle.Turtle()
    t.shape("turtle")
    circle_size = 80    # A number (integer) for size
    color = "orange"    # A word (string) for color
    is_big = True       # Yes/no (boolean) to check size
    t.color(color)
    if is_big:
        t.circle(circle_size)
        print("Drew a big circle with size " + str(circle_size) + "!")
    else:
        t.dot(circle_size)  # Small dot if not big
    turtle.done()
  • Explanation:
    "circle_size is a number (integer), color is a string (words in quotes), and is_big is a boolean (True/False). if decides what to draw. Is color a number? No—try changing circle_size to 50!"
  • Interactive Step:
    "Set circle_size to 60 and color to ‘purple’. Is is_big True or False? Run it!"
  • Exercise:
    "Use shape_size (70), shape_color ("red"), and is_tall (False). If is_tall, draw a tall rectangle; else, a circle."
  • Mini-Project: Shape Experiment
    • Task: "Pick a size (number), my_color (word), and is_fun (True/False). If is_fun, draw a star; else, a circle."
    • Outcome: "Share your experiment!"

Week 2: Control Flow – Guiding Turtle’s Path

Session 1: If Statements with Turtle

  • Topic: Let’s make Turtle choose its drawing!
  • Teaching Moment:
    "You’re doing great! Let’s use if to let Turtle decide. Should it draw a big shape or small one? Let’s think together!"
  • Interactive Demo (turtle_if.py):
    "I’m drawing a shape. Should it be big if the size is over 60?"
    • Kids: "Yes!"
    • Teacher: "Cool! Let’s use size—what number?"
    • Kids: "70!"
    • Teacher: "Great! What color?"
    • Kids: "Green!"
  • Sample Code (turtle_if.py):
    import turtle
    
    t = turtle.Turtle()
    t.shape("turtle")
    size = 70
    color = "green"
    t.color(color)
    if size > 60:
        t.circle(size)
        print("Big circle drawn!")
    else:
        t.square(50)  # Hypothetical, use forward/right for square
        print("Small shape!")
    turtle.done()
  • Explanation:
    "if size > 60 checks the size. If true, it draws a circle; else, a square. Fix the square with a loop—add for i in range(4): t.forward(50); t.right(90)!"
  • Interactive Step:
    "Change size to 40. What happens? Why?"
  • Exercise:
    "Use temp (50). If above 40, draw a circle; else, a triangle with right(120) three times."
  • Mini-Project: Weather Art
    • Task: "Use temp (e.g., 45). If above 30, draw a sun (circle) in yellow; else, a snowflake (small squares)."
    • Outcome: "Show your weather art!"

Session 2: Loops with Turtle

  • Topic: Let’s repeat drawings with loops!
  • Teaching Moment:
    "Fantastic choices! Loops make Turtle draw again and again. Should we draw 5 stars or 3? Let’s decide!"
  • Interactive Demo (turtle_loop.py):
    "Let’s draw stars. How many?"
    • Kids: "4!"
    • Teacher: "Awesome! What size for each?"
    • Kids: "60!"
    • Teacher: "Great! What color?"
    • Kids: "Red!"
  • Sample Code (turtle_loop.py):
    import turtle
    
    t = turtle.Turtle()
    t.shape("turtle")
    num_stars = 4
    star_size = 60
    color = "red"
    t.color(color)
    for i in range(num_stars):
        for j in range(5):
            t.forward(star_size)
            t.right(144)
        t.penup()
        t.forward(100)
        t.pendown()
    turtle.done()
  • Explanation:
    "The outer for repeats num_stars times. The inner for draws one star with right(144). penup() moves without drawing. Try num_stars = 3!"
  • Interactive Step:
    "Change star_size to 40. How does it look?"
  • Exercise:
    "Draw 3 hexagons (6 sides) with right(60) and a size of 50, moving right each time."
  • Mini-Project: Loop Garden
    • Task: "Draw 5 shapes (e.g., squares) with a loop, using size (70) and color ("blue"), moving right."
    • Outcome: "Show your garden!"

Week 3: Functions and Lists – Reusable Designs

Session 1: Creating Functions with Turtle

  • Topic: Let’s make reusable drawing spells!
  • Teaching Moment:
    "You’re loop experts! Functions let us reuse code. Should we draw a house or a tree? Let’s build a function!"
  • Interactive Demo (turtle_function.py):
    "Let’s draw a house. What shape for the roof?"
    • Kids: "Triangle!"
    • Teacher: "Great! What size for the base?"
    • Kids: "100!"
    • Teacher: "Cool! What color?"
    • Kids: "Brown!"
  • Sample Code (turtle_function.py):
    import turtle
    
    def draw_house(t, base_size, color):
        t.color(color)
        for i in range(4):  # Base
            t.forward(base_size)
            t.right(90)
        t.penup()
        t.goto(-base_size/2, base_size)
        t.pendown()
        for i in range(3):  # Roof
            t.forward(base_size)
            t.right(120)
    
    t = turtle.Turtle()
    t.shape("turtle")
    draw_house(t, 100, "brown")
    t.penup()
    t.goto(150, 0)
    t.pendown()
    draw_house(t, 50, "green")
    turtle.done()
  • Explanation:
    "draw_house takes t, base_size, and color. We draw a square base and triangle roof. Try draw_house(t, 80, "red")!"
  • Interactive Step:
    "Add a new draw_house call with a different size and color. Where does it go?"
  • Exercise:
    "Make a draw_star(t, size) function with right(144) five times. Call it with 40."
  • Mini-Project: House Village
    • Task: "Create a draw_house function. Draw 3 houses with different sizes and colors."
    • Outcome: "Show your village!"

Session 2: Lists and Patterns

  • Topic: Let’s use lists for colorful patterns!
  • Teaching Moment:
    "Nice village! Lists hold many values. Should we draw 4 shapes in different colors? Let’s plan it!"
  • Interactive Demo (turtle_list.py):
    "How many shapes?"
    • Kids: "3!"
    • Teacher: "Great! What sizes?"
    • Kids: "50, 70, 90!"
    • Teacher: "Awesome! What colors?"
    • Kids: "Red, blue, yellow!"
  • Sample Code (turtle_list.py):
    import turtle
    
    t = turtle.Turtle()
    t.shape("turtle")
    sizes = [50, 70, 90]
    colors = ["red", "blue", "yellow"]
    for size, color in zip(sizes, colors):
        t.color(color)
        for i in range(4):
            t.forward(size)
            t.right(90)
        t.penup()
        t.forward(120)
        t.pendown()
    turtle.done()
  • Explanation:
    "sizes and colors are lists. zip() pairs them. The loop draws a square for each pair. Add a size and color!"
  • Exercise:
    "Use lists for 3 sizes and colors. Draw triangles with right(120)."
  • Mini-Project: Rainbow Pattern
    • Task: "Use lists for 4 sizes and colors. Draw circles, moving right each time."
    • Outcome: "Share your rainbow!"

Week 4: Games and Final Project – Turtle Adventures

Session 1: Interactive Turtle Games

  • Topic: Let’s make Turtle move with keys!
  • Teaching Moment:
    "You’re pattern pros! Let’s make Turtle a game character. Should it move up or down? Let’s decide!"
  • Interactive Demo (turtle_game.py):
    "Which way should Turtle move first?"
    • Kids: "Up!"
    • Teacher: "Great! What about down?"
    • Kids: "Yes!"
  • Sample Code (turtle_game.py):
    import turtle
    
    t = turtle.Turtle()
    t.shape("turtle")
    
    def move_up():
        t.setheading(90)
        t.forward(30)
    
    def move_down():
        t.setheading(270)
        t.forward(30)
    
    turtle.listen()
    turtle.onkey(move_up, "Up")
    turtle.onkey(move_down, "Down")
    turtle.done()
  • Explanation:
    "setheading() turns Turtle. onkey() links keys to moves. Add move_right() with setheading(0)!"
  • Interactive Step:
    "Add a move_right function. Test it with ‘Right’!"
  • Exercise:
    "Add a function to change t.color("purple") on ‘space’."

Session 2: Final Project Work and Presentation

  • Topic: Build and showcase your Turtle world!
  • Teaching Moment:
    "Time for your big project! Let’s create a Turtle race. Where should the finish line be? Let’s plan it!"
  • Interactive Demo (turtle_race.py):
    "How many turtles?"
    • Kids: "2!"
    • Teacher: "Great! What colors?"
    • Kids: "Red, blue!"
  • Exercise:
    "Add a loop to draw a start line with 5 dots."
  • Mini-Project: Turtle Race Prep
    • Task: "Set up 2 turtles with different colors and starting positions."
  • Final Project: Turtle Race Game
    • Sample Code (turtle_race.py):
      import turtle
      import random
      
      # Set up screen
      screen = turtle.Screen()
      screen.title("Turtle Race")
      
      # Create turtles
      t1 = turtle.Turtle()
      t1.shape("turtle")
      t1.color("red")
      t1.penup()
      t1.goto(-200, 100)
      
      t2 = turtle.Turtle()
      t2.shape("turtle")
      t2.color("blue")
      t2.penup()
      t2.goto(-200, -100)
      
      # Race function
      def race():
          while t1.xcor() < 200 and t2.xcor() < 200:
              t1.forward(random.randint(1, 20))
              t2.forward(random.randint(1, 20))
          if t1.xcor() >= 200:
              print("Red turtle wins!")
          else:
              print("Blue turtle wins!")
      
      race()
      turtle.done()
    • Presentation: "Explain how your race works—variables, loops, and wins!"
    • Outcome: A fun, visual race game.

Tips for Teaching

  • Interactive: "Which turtle should win? Let’s adjust the speed!"
  • Encouragement: "You’re a Turtle champion! Keep creating!”
  • Support: Help with setup and guide reasoning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment