Polygon Procedures: Code That Reuses Itself

← Free Lesson Plans for Teachers

Free Lesson Plan

Grade 6Math & Engineering2 sessions x 45 minFinch2-AP-142-AP-12

⬇ Download PDF (lesson, student sheets & answer key)

Driving question: How can one procedure draw any regular polygon?

Overview

Students program a Finch robot with a marker to draw regular polygons, discover that the robot's turn at each corner is 360 divided by the number of sides, and write a procedure (function) with parameters for the number of sides and the side length.

In Session 2 they nest their polygon procedure inside a second loop to draw rotating patterns and test the procedure with a range of inputs, including ones that should fail.

Standards

CodeStandard
CSTA 2-AP-14 (2017)reusable program parts that take inputs
CSTA 2-AP-12 (2017)programs with loops inside loops and decisions

CSTA codes are from the 2017 CSTA K-12 Computer Science Standards and show which standards this lesson practices. This lesson has not been reviewed or endorsed by CSTA. CSTA released revised PK-12 standards in 2026.

Learning Objectives

Students will:

  • explain why the turn angle for a regular polygon is 360 / n.
  • create a procedure with parameters to draw any regular polygon.
  • combine loops (nested loops) to make a pattern and test a range of inputs.

Materials

Geyer resources for this lesson

Also needed

  • 1 computer or Chromebook per group with Snap!, MakeCode, or Python (procedures/functions are needed). Python also needs BirdBrain's BlueBird Connector (Windows, Mac, or Chromebook).
  • Large paper on the floor (1 sheet per group)
  • Crayola Paint Brush Pens for the Finch pen mount (BirdBrain's recommended fit), or the 5 pens that come with the Finch Classroom Flock. Geyer does not currently sell these pens.
  • Student Sheets 1 and 2, 1 copy per student (below and in the PDF)

Vocabulary

WordWhat it means
regular polygonA polygon with all sides equal and all angles equal.
exterior (turn) angleHow far the robot turns at a corner; for regular polygons, 360 / n.
procedure (function)A named set of instructions that can be used again.
parameterAn input to a procedure, such as the number of sides.
nested loopA loop inside another loop.

Safety Notes

  • Run Finch robots on the floor or inside a boxed-in area such as the Finch Arena or a taped zone. A Finch can drive off a table edge.
  • Keep walkways clear of robots and charging cables while students move around the room.
  • Use washable markers; cap them before carrying the robot.

Before You Teach

  • Test a square and a hexagon on your paper; note the speed that gives clean corners.

Warm-Up (5 min)

  • Walk a triangle as a class. Ask: "How much did we turn in all when we got back to the start?" (One full turn, 360 degrees.)

Procedure

Find the pattern (20 min)

  1. Teams draw a square, triangle, and hexagon and fill in the table on Student Sheet 1.
  2. Discover: total turning = 360 degrees, so each turn = 360 / n.

Write the procedure (20 min)

  1. Define polygon(sides, length): repeat sides times: move forward length, turn right 360 / sides.
  2. Call polygon(5, 15) and polygon(8, 10). Check by measuring with a protractor.

Nested pattern (Session 2) (20 min)

  1. Repeat 6 times: polygon(4, 15), turn right 60. Predict the drawing, then run it.

Test cases (15 min)

  1. Test the procedure with n = 3, 10, 2, 1, and 0. Record what happens on Student Sheet 2.
  2. Add a check: if sides is less than 3, show an error on the micro:bit instead of driving.

Share (10 min)

  1. Teams explain one test case that broke the procedure and their fix.

Differentiation

SupportOn-levelChallenge
• Give the procedure shell with blanks.
• Use only n = 3, 4, 6.
• Provide a turn-angle chart.
• Complete the procedure and student sheets as written.• Add a parameter for color and change the beak color for each shape.
• Draw a star polygon (turn 144 degrees, 5 times) and explain the total turning.
• Compute the interior angle: 180 - 360 / n.

Assessment

  • Check the table pattern.
  • Read procedure definitions for correct use of parameters.
  • Review test case results.

Exit ticket: "Write a call to your procedure to draw a regular nonagon (9 sides) with 12 cm sides. What is each turn?" (polygon(9, 12); 40 degrees.)

CriterionBeginningDevelopingProficient
Turn angle reasoningNot yetUses formulaExplains why each turn is 360 / n
Procedure with parametersHard-codedOne parameterTwo parameters, reused correctly
TestingOne caseSeveral casesIncludes edge cases and fixes errors

Extensions

  • Use the pattern to draw a "circle" with 36 sides and discuss why it looks round.
  • Port the procedure to Python (install BirdBrain's BlueBird Connector so the computer can talk to the Finch).
  • Make a class mural of nested polygon art.

Student Sheets

Use these sheets in class, or download the PDF for a print-ready layout.

Student Sheet 1

The Turn Pattern

Print-ready version in the PDF.

Name: ______________________________   Date: ______________

ShapeSides (n)Turn at each cornerTotal turning
Triangle3
Square4
Pentagon5
Hexagon6
Octagon8
Turn 120° at each cornerTurn 72° at each cornerTurn 45° at each corner

Rule for the turn angle of a regular polygon with n sides:

Student Sheet 2

Procedure and Test Cases

Print-ready version in the PDF.

Name: ______________________________   Date: ______________

Write your procedure:

define polygon(sides, length):
Test callPredictionWhat happenedPass or fix?
polygon(3, 20)
polygon(10, 8)
polygon(2, 20)
polygon(1, 20)
polygon(0, 20)

What check did you add so the procedure handles bad inputs?

Show answer key (for teachers)

Answer Key & Teacher Notes

  • Turns: triangle 120, square 90, pentagon 72, hexagon 60, octagon 45 degrees. Total turning is always 360 degrees.
  • Rule: turn = 360 / n.
  • Procedure: define polygon(sides, length): repeat sides: forward length; turn right 360 / sides.
  • Test cases: (3, 20) triangle; (10, 8) decagon; (2, 20) the robot drives forward, turns 180, and drives back over the same line (not a polygon); (1, 20) drives forward and turns a full 360 (a line); (0, 20) does nothing (the loop runs 0 times); a divide-by-zero error happens only if you compute 360 / sides before the loop.
  • Check: if sides < 3, show an error (for example, an X on the micro:bit) and stop.
  • Exit ticket: polygon(9, 12); each turn 40 degrees.

Teacher notes

The turn the robot makes is the exterior angle. Students may confuse it with the interior angle they measure inside the drawn shape; interior = 180 - exterior for each corner.

Need a print-ready copy? The PDF includes the lesson, student sheets, and answer key.

Download the PDF  |  All free lesson plans

Free for classroom use. You may print and copy this lesson for your students. © Geyer Instructional Products. Standards text: CSTA K-12 CS Standards © CSTA.