You are on page 1of 14

Educator Guide

Python 101 - Lesson 8


60 minutes

Planting A Seed
FUNCTIONS

EDUCATION.MINECRAFT.NET
1
THEME OVERVIEW
In this lesson, students will help CodingMine develop the Agent to prepare the soil
in an ecological area for the planting a large number of trees.

LESSON OBJECTIVES
By the end of the lesson, students will:
• Learn and apply the coding concept of functions
• Utilize in code comments

KEY VOCABULARY
Functions – Specially made command that executes a group of commands.
Comments – Pieces of text in a code that the computer does not run. They tell the
developer what the code does.

CODING CONCEPTS
• Functions
Functions are an integral part of most coding languages, especially in
Python. Functions are a specially made command that can execute a group
of commands (or any piece of code). Functions are a great way to shorten a
code and make it less confusing because we can replace repetitive parts,
often sequences, with our own functions.
To write a function in Python, we first need to write out the syntax def, which
stands for define. By doing this, we are telling the computer that we want to
make (or define) our own function.
After the def comes the function_name. This is the name we are going to
give our function. We are then going to ‘call’ the function_name later to use
our function in our code. When naming a function, we should follow the
same rules as when naming a variable. After the name, there is a pair of
brackets followed by a colon. After the colon, any code that is indented
below it belongs to that function. An example of a custom-made function
would be:

Def function_name():
My code…

Once we have created a function, we can then use that function in our code
by writing out the function_name followed by a pair of brackets and a
colon. This is commonly referred to as ‘calling a function’:

2
Function_name():

• Comments
A great way to organize and annotate a code is to use comments.
Comments are pieces of text in a code that the computer does not run.
Comments are mainly written so that any developer can look at a code and
clearly understand what each part of the code does. To comment a line of
text in Python, you need to write a hashtag before it.
• Methods
You will be using methods in this lesson to control the contents and the
arrangement of content in lists. Methods are special commands that affect
data in many ways.

1. my_list.sort() – Sorts a list in alphabetical order


2. my_list.reverse() – Reverses the order of the contents
3. my_list.append() – Adds another value to the end of a list
4. my_list.pop() – Removes a value from a list

LESSON ACTIVITIES
Direct Instruction (Teacher-Led; “I Do”)
Today, we will continue working in our computer science unit, “Python 101”. The
lesson for today is called “Planting a Seed”. (slide 1)

Review the lesson objectives with students. (slide 2)

Define the important vocabulary with students. (slide 3)

“CodingMine wants to develop the Agent to help an ecological organization. This


organization wants to plant a large number of trees and they must do it very
quickly as they have a deadline. However, it is not an easy job to prepare the soil to
plant pastures of saplings. That is why the organization wants to use the Agent,
but the developers have been having some problems with their code.” (slide 4)

Explain the coding concept focus for students. (slide 5)

Guided Instruction (Teacher Modeling; “We Do”)


Demonstrate how to locate and find the Python 101 lesson, “Planting a Seed” from
the in-game library. Showcase the spawn point for students and then explain that

3
they will start their lesson by talking to the NPC, the CEO of CodingMine. (slides 6-
8)

All students should log into Minecraft: Education Edition at this point and replicate
these exact steps so you can complete the first activity together.

Activity 1: One Row at a Time (Slides 9-16)


Objective: Code the Agent to till, plant, and fertilize trees

Explanation:
The developer needs their help to code the Agent to till, plant, and fertilize a row of
trees in their planting spots.
(Hint: Tilling means to ‘prepare a piece of soil’ for planting)
Since the spaces in between the planting spots are not identical, you cannot use a
simple for loop. The best way to complete this activity is by making a function with
the sequence of actions that the Agent must make.
(Hint: The Agent already has saplings in its first inventory spot, and fertilizer in its
second)
• Part 1: Code the Agent to move forward while tilling and planting saplings
on the grass blocks to its left. Make a function in the dedicated area of the
coding window; inside the function, you need to write a sequence making
the Agent till and place a sapling to its left. Then write some code to make
the Agent move forward, while calling their function at certain intervals.
(Hint: Tell the students to write #comment about what each function does
throughout the lesson)
• Part 2: Add to the code so that the Agent places fertilizer on each sapling
five times. Change between the Agent’s inventory slots, 1 and 2, each time.
Explain to the students that as they have written a function for the Agent’s
tree planting sequence, an advantage of using functions is that they only
have to change the code in that function, rather than changing it each time
in the main code.

When the code is run the Agent will move forward, and, on the grass blocks, till,
plant saplings, and fertilize them. When the Agent finishes the task and gets to the
gold block, Activity 1 in complete.
(Hint: Not all trees need to grow immediately, just a minimum of one tree needs
to be fully grown)

4
Code snippets:

5
Independent Work (Teacher Support; “You Do”)
Activity 2: Breaking Boulders (Slides 17-24)
Objective: Write code for the Agent to clear the ground of rocks and then plant
saplings

Explanation:
The next developer need your help to code the Agent to clear the ground of rocks
and then till and plant saplings in their planting spots. You need to use more
complex pieces of code with their functions.
• Part 1: Make the Agent move forward and break each STONE block in its
path. Tell them to do this by writing a function to make the Agent break the
block in front of it, collect it and move forward.
• Part 2: You need to make the Agent do the same thing while also tilling the
soil and planting saplings. When the code is run, the Agent will move
forward, breaking each stone, and till and plant saplings on the grass blocks.

6
(Hint: The parameters for the Agent till and place commands need to be set
to back, as the Agent cannot till and plant on the block it is standing on)

When the Agent finishes the task and gets to the gold block, Activity 2 is complete.

Code snippets:

7
Activity 3: Pasture of Trees? (Slides 26-31)
Objective: Write code to have the Agent plant saplings across a large area only on
grass blocks

Explanation:
The next developer needs your help to code the Agent to move across a large area
and plant saplings only on the grass blocks. To make the Agent move, pass over
every block in an area that would, up until now, have used a nested loop, but this is
no longer necessary as we can do the same action using functions.
• Part 1: Code three new functions with sequences, one to make the Agent
move forward, one to turn left, and one to turn right. Use these functions in
a for loop to make the Agent pass over every block in the area, row by row,
until it reaches the gold block.
• Part 2: Add to the code to make the Agent till the grass blocks that it passes
over and plant a sapling. Add an if else conditional, that inspects for grass
blocks, in their function that moves the Agent forward. When the code is run
the Agent will till the soil and plant a sapling.

When the Agent finishes the task and gets to the gold block, Activity 3 and the
lesson are complete.

8
Code Snippets:

9
10
LESSON CONCLUSION
Ask students about the skills that they have learned during the lesson to reinforce
the concepts learned. (Slides 32-33)

1. What is a function?
Answer: A function is a command you can create that can run a group of
other commands, or any piece of code, when called.
2. Why are functions useful?
Answer: Functions are a great way to shorten repetitive code and make it
more organized.

11
3. What are comments?
Answer: Comments are pieces of text, useful for the developer, inserted
in a code that the computer does not run.
4. How do you write a comment?
Answer: Comments are written by placing a # before the text.

These questions are also available as a printable handout at the end of this
document. They can be used as a formative assessment for this lesson’s learning
objectives.

12
EDUCATIONAL STANDARDS
UNITED STATES: CSTA
• 3A-AP-16 Design and iteratively develop computational artifacts for practical
intent, personal expression, or to address a societal issue by using events to
initiate instructions.
• 3A-AP-23 Document design decisions using text, graphics, presentations,
and/or demonstrations in the development of complex programs.

UNITED STATES: ISTE


● 1.5.a Students formulate problem definitions suited for technology-assisted
methods such as data analysis, abstract models and algorithmic thinking in
exploring and finding solutions.
● 1.5.c Students break problems into component parts, extract key
information, and develop descriptive models to understand complex
systems or facilitate problem-solving.

AUSTRALIAN F-10 CURRICULUM: DIGITAL TECHNOLOGIES (YEAR 9 AND


10)
● Designing algorithms to solve real-world problems and describing
algorithms using flow charts and structured English (ACTDIP040)
● Recognising that different algorithms can solve a problem with different
trade-offs (ACTDIP040)
● Considering different algorithms and selecting the most appropriate based
on the type of problem (ACTDIP041)

UK NATIONAL CURRICULUM: COMPUTING (KEY STAGE 4)


• Develop and apply their analytic, problem-solving, design, and
computational thinking skills

13
NAME: _______________________________________________________ DATE: _____________________________

PYTHON 101: LESSON 8 FORMATIVE ASSESSMENT

What is a function?

Why are functions useful?

What are comments?

How do you write a


comment?

14

You might also like