Lesson plan

Python 101 with MakeCode - Lesson 8

Students use Python functions and comments to direct the Agent to prepare soil, clear boulders, and plant trees for an ecological organization.

Python 101 with MakeCode - Lesson 8
Ages
Ages 11+
Duration
1 hour
Essential question

How do functions and comments help programmers organize code and solve irregular patterns?

Overview

In this computer science lesson, students learn how to define and execute functions and insert in-code comments using Python. By grouping repeated actions into a single named function, learners see how to shorten code, reduce clutter, and handle tasks where regular loops are impractical.

Students apply these programming skills within Minecraft to support an ecological initiative through CodingMine. Using the Agent, learners automate environmental labor such as tilling soil, breaking rocks, and planting saplings across irregular plots and open pastures.

Learning objectives

By the end of this lesson students will be able to:

  • Define a function and explain how it groups commands together.
  • Write and call custom functions to automate planting routines.
  • Insert explanatory in-code comments using proper syntax.
  • Program the Agent to identify grass blocks and clear obstacles across varied plots.

Blocks and items used in this lesson

Key vocabulary

Function
A user-created command that executes a grouped sequence of code instructions when called.
Comment
Text written in the code to assist human developers, which is ignored by the computer during execution.
Till
To prepare a section of soil so that it is ready for planting.

Before class

Lesson sequence

Suggested timing: about 60 minutes in total.

  1. Introduction to Functions and Comments10 min

    Introduce the coding concepts using the lesson presentation. Explain that a function lets programmers bundle several actions under one command name to avoid rewriting repetitive code. Demonstrate how to write in-code comments using the # symbol to leave notes that the computer ignores.

  2. Activity 1: One Row at a Time15 min

    Present the ecological project to the class and explain that tilling means preparing soil for planting. Because the spaces between planting spots are irregular, a standard loop will not work. Guide students to define a custom function that commands the Agent to till, plant, and fertilize, calling it at each designated spot.

  3. Activity 2: Breaking Boulders15 min

    Have students assist the second developer with a rockier area. Students expand their function logic to code the Agent to break ground boulders before tilling the soil and planting saplings.

  4. Activity 3: Pasture of Trees15 min

    Challenge students to move the Agent across a large field. Rather than relying on a nested loop to cover the area, students apply functions to navigate the pasture and plant saplings strictly on grass blocks.

  5. Review and Formative Assessment5 min

    Conclude the lesson by asking the assessment questions about the purpose of functions, their benefits, and how to format comments in Python code.

Assessment: success criteria

  • State the definition of a function and why it is useful for organizing code.
  • Demonstrate how to write an in-code comment with a hashtag symbol.
  • Create a function that directs the Agent to till, plant, and fertilize.
  • Program the Agent to inspect terrain and plant saplings only on grass blocks.

Differentiation

Support

Provide students with code starter templates showing the proper syntax for defining and calling a function.

Stretch

Ask advanced learners to write multiple modular functions to handle varying types of obstacles across the field.

Knowledge check

5 questions to check understanding after the lesson. Tap an answer to see if it is right; the score appears at the end.

  1. 1What is a function in programming?

  2. 2Why could students not use a simple for loop in Activity 1?

  3. 3Which symbol is placed before text to create an in-code comment in Python?

  4. 4What does the term 'tilling' mean in the context of this lesson?

  5. 5In Activity 3, what rule must the Agent follow when planting saplings across the pasture?

Resources

Part of the Python 101 curriculum

This is lesson 8 of 10 in Python 101.

  1. Python 101 with MakeCode - Lesson 1
  2. Python 101 with MakeCode - Lesson 2
  3. Python 101 with MakeCode- Lesson 3
  4. Python 101 with MakeCode - Lesson 4
  5. Python 101 with MakeCode - Lesson 5
  6. Python 101 with MakeCode - Lesson 6
  7. Python 101 with MakeCode - Lesson 7
  8. Python 101 with MakeCode - Lesson 8
  9. Python 101 with MakeCode - Lesson 9
  10. Python 101 with MakeCode - Lesson 10

Frequently Asked Questions

Why use functions instead of nested loops in Activity 3?

Functions enable students to package movement and inspection routines into modular commands, accomplishing the same area coverage without the complexity of nested loops.

Do comments change how the Agent behaves in Minecraft?

No. Comments are completely ignored by the computer and are only meant to help the programmer read and organize their code.

Adapted from Python 101 with MakeCode - Lesson 8 by Minecraft Education on Minecraft Education, last updated Jun 14, 2023. This classroom version, the timings and the quiz were written by 9Minecraft Education.

You May Also Like

9Minecraft Education is an independent teaching resource and is not affiliated with Mojang or Microsoft. Lesson plans here are our own classroom-ready adaptations; each one links to the original resource and credits its author. © 2026 9minecraft.net