How to use the
Learning Portal

Learning Portal

Our hands-on, comprehensive lesson plans span a range of levels. Browse our free STEM and coding learning resources.

Marty Image

3.9 A Loopy introduction

45 Minutes

Lesson Overview

As students have been exploring Python with Marty, they may have noticed a lot of repetition in their lines of code. As a class, students will explore where this repetition might happen and try out different methods to reduce the number of lines in their programs. Students will create a shape guessing program for Marty.

Key vocabulary:
    Python, Repeat / Loop, For Loop, Repetition, Flowchart,

Content Sections

  • Learning Objectives
  • Extensions & Challenges
    • Additional Reading
    • 3.9 A Loopy introduction

      45 Minutes

      Lesson Overview

      As students have been exploring Python with Marty, they may have noticed a lot of repetition in their lines of code. As a class, students will explore where this repetition might happen and try out different methods to reduce the number of lines in their programs. Students will create a shape guessing program for Marty.

      Key vocabulary:
        Python, Repeat / Loop, For Loop, Repetition, Flowchart,
      • 3.1, 3.2, 3.5, 3.6
      • Laptop or PC
      • Technologies/Literacy/Numeracy
        • Marty the Robot
        • Student workbooks (Lesson 1)
        • Devices with a Python editor and martypy installed

      Learning Objectives

      • Highlight where a loop/repeat statement could be used to reduce repetition
      • Examine the flow of their programs and draw flowchart diagrams
      • Write a for loop in Python with the correct parameters for the purpose

      1. Class discussion of the ways that we can reduce the amount of repetition in our programs

      2. Challenge students to write instructions for coding someone to walk in a square and highlight where the repetition appears

      3. Introduction to loops as a way to repeat the instructions and highlight structure of a flowchart for a loop

      4.Show students example instructions with the challenge to pair the instruction up to the correct shape

      5. Script example on how you can use loops in Python with special attention given to the indentation required for loops (similar to if statements)

      6. Challenge students to create a shape guessing program that asks the user question, guesses the shape and shows the answer by coding Marty to walk out in that shape

      a. Demonstration of script provided for this lesson to show students an example of tackling the problem

      7. Demonstrate flowcharts for planning programs and encourage students to plan their programs first by drawing a flowchart and then starting to code in their small groups with Marty

      Extensions & Support

      • Extend the program to use the Python Turtle library to draw Marty’s path on the screen (Technologies/Literacy/ Numeracy/Arts)
      • What is the least number of questions students could ask to narrow down the selected shape? (Technologies/ Literacy/Numeracy)

      Additional Reading

      • Marty the Robot Educator Guide
      • Educator FAQ
      • Getting Started with Python
      • MartyPy Documentation