
- Type
- Lesson plan
- Subject
- Computer Science & Coding
- Grade
- Middle school (Grades 6-8)High school (Grades 9-12)Adults & educators (Higher education and teacher learning)
- Ages
- Ages 11+
- Duration
- 1 hour
- Level
- Intermediate
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.
- 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.
- 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.
- 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.
- 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.
- 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
Provide students with code starter templates showing the proper syntax for defining and calling a function.
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.
1What is a function in programming?
Answer: D. A function is a custom command designed to run a group of code instructions whenever it is called.
2Why could students not use a simple for loop in Activity 1?
Answer: B. Because the intervals between the planting locations varied, a standard for loop could not handle the irregular spacing.
3Which symbol is placed before text to create an in-code comment in Python?
Answer: C. In Python, placing a # symbol before text turns it into a comment that the computer ignores.
4What does the term 'tilling' mean in the context of this lesson?
Answer: A. The lesson notes explain that tilling means to prepare a piece of soil for planting.
5In Activity 3, what rule must the Agent follow when planting saplings across the pasture?
Answer: D. Students are instructed to code the Agent to traverse the large area and place saplings only on grass blocks.
Resources
- Lesson package (.zip)Everything the author attached to this lesson in one download.
- Python 101-Lesson 8: Planting a SeedEDU Guide
- Python 101-Lesson 8: Planting a SeedPresentation
- Programming with PythonCurriculum Overview
- Lesson worldOpens the world page in Minecraft Education (sign-in with a school account may be needed).
Part of the Python 101 curriculum
This is lesson 8 of 10 in Python 101.
- Python 101 with MakeCode - Lesson 1
- Python 101 with MakeCode - Lesson 2
- Python 101 with MakeCode- Lesson 3
- Python 101 with MakeCode - Lesson 4
- Python 101 with MakeCode - Lesson 5
- Python 101 with MakeCode - Lesson 6
- Python 101 with MakeCode - Lesson 7
- Python 101 with MakeCode - Lesson 8
- Python 101 with MakeCode - Lesson 9
- 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.























