1044144327939486-Python 101 - Lesson 6 - Driving Around - EDU Guide
1044144327939486-Python 101 - Lesson 6 - Driving Around - EDU Guide
Driving Around
CONDITIONALS AND BOOLEAN LOGIC
EDUCATION.MINECRAFT.NET
1
THEME OVERVIEW
In this lesson, students will help CodingMine code the Agent to drive a car. This will
require decision-making and analyzing the road by using conditionals and Boolean
logic.
LESSON OBJECTIVES
By the end of the lesson, students will:
• Understand the coding concepts of conditionals
• Understand the concept of Boolean logic
• Understand how to use if, if else and elif conditionals
• Understand how to use Boolean logic with conditionals
KEY VOCABULARY
Indentation – utilized to declare a piece of code belongs to the code above
Compare – utilized when comparing two statements
CODING CONCEPTS
• Boolean Logic
Combines multiple logic statements that are either True or False into an
expression that is either True (1) or False (0).
• AND operator
This operator looks at two Boolean statements and if they both are true (1)
the operator will give us back a 1. However, if either one of those statements
are false, then the operator will give us back a 0.
• NOT operator
This operator looks at a Boolean statement and flips it. This means, if the
statement is 0 using the NOT operator will flip it to a 0.
• Conditionals
o The if command is a conditional and will only run the code inside it if
a desired condition is met (true). Tell the students that the outcome of
a condition can only be true or false (1 or 0).
o The if else command almost works in the same way. However, if the
condition in the if conditional is not met (0) the else conditional will
then run another piece of code.
o The elif is a command that is placed after an if command and has its
own defined condition. If the condition is true (1), the piece of code
inside it will run.
2
Any conditional is basically an action to be taken if something is true or
false. Tell the students that they are already using this concept in their
everyday life. Some examples would be:
1. IF you have finished your homework, you can go out and play.
2. IF you like to play football, you can come with us to the pitch.
3. IF you like basketball I have a hoop in my backyard, ELSE we could
play a board game.
SYNTAX / OPERATORS
Compare = =
Double equals or compare is used when we want to compare two statements
(Boolean, numerical or string). The double equal signs are used with conditionals,
to compare the defined condition against the Minecraft world or coding outcome.
Indentation
Indentations in Python are used when we want to declare that a piece of code
belongs to the command above. To indent a piece of code, use the tab key on the
keyboard.
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 “Driving Around”. (slide 1)
“You need to help CodingMine further develop the Agent. CodingMine wants to
code the Agent so that it can drive a car by itself. However, this means that the
Agent needs to be able to make decisions and analyze the road for any obstacles
and signs. To do this in a safe manner, before testing the Agent on the actual road,
the students will be coding the Agent in a number of simulated traffic situations.
You will help code the Agent using conditionals and Boolean logic.” (slide 4)
3
Demonstrate how to locate and find the Python 101 lesson, “Location, Location,
Location” from the in-game library. Showcase the spawn point for students and
then explain that they will start their lesson by talking to the NPC, the CEO of
CodingMine. (slides 7-9)
All students should log into Minecraft: Education Edition at this point and replicate
these exact steps so you can complete the first activity together.
Explanation:
The developer needs your help to write some code to make the Agent understand
traffic lights. In part 1, the Agent should keep moving when green blocks are to its
left. In part 2, the Agent should stop when there is a red block to its left. In part 3,
the Agent should wait for 2 seconds when there is a yellow block to its left and
then continue to the gold.
• Part 1: Make the Agent move when there is a block to its left. When the
students run the code, the Agent will move forward when there is block on
its left side.
(Hint: Tell the students to replace the word ‘True’ in the conditional and
place their condition instead)
• Part 2: Make the Agent stop when the light is red. When the students run
the code, the Agent will move forward when there is not a block on its left
side.
• Part 3: Make the Agent wait for 2 seconds once it is at the yellow light.
(Hint: Explain to the students that 1000 milliseconds is the same as 1
second)
Now when the students run the code, the Agent will move forward until there is a
block on its left side. Then it will wait for around two seconds (this may depend on
the computer speed) and continue. When the Agent reaches the last gold block,
the activity is complete.
Code snippets:
4
Independent Work (Teacher Support; “You Do”)
Activity 2: Is It Left, or Right (Slides 16-22)
Objective: Code the Agent to read road signs and navigate busy streets
Explanation:
The programmer needs your help to write some code to make the Agent able to
navigate busy streets by reading road signs. The Agent will have to stop and turn
in differenct directions depending on the signs on a simulated road. This activity
will happen in two parts:
• Part 1: Make the Agent turn left once it reaches the sign and continue to the
gold block. When you run the code, the Agent will move forward until it
5
reaches the turn sign, after which it will go in the direction of that sign,
finally stopping on the gold block.
• Part 2: Make the Agent move forward, turing left and right, until it reaches
the gold block. When you run the code, the Agent will move forward until it
reaches a turn sign, after which it will go in the direction of that sign.
Code snippets:
6
Activity 3: Getting Through (Slides 23-26)
Objective: Write code to detect obstacles to navigate through a course
Explanation:
The AI developer needs your help to write an obstacle detection code to make the
Agent navigate through a course with randomly placed blocks. The Agent should
be able to get to the end, no matter where the blocks are placed. Once the Agent
detects a block, it will be highlighted.
When the students have written the conditionals and the correct conditions inside,
the Agent will be able to navigate through the course by detecting the block in
front of it. When the Agent reaches the gold block, Activity 3 and the lesson are
complete.
Code Snippets:
7
LESSON CONCLUSION
Ask students about the skills that they have learned during the lesson to reinforce
the concepts learned.
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.
8
EDUCATIONAL STANDARDS
UNITED STATES: CSTA
• 3A-AP-14 Use lists to simplify solutions, generalizing computational
problems instead of repeatedly using simple variables.
• 3A-AP-15 Justify the selection of specific control structures when trade-offs
involve implementation, readability, and program performance, and explain
the benefits and drawbacks of choices made.
• 3A-AP-18 Create artifacts by using procedures within a program,
combinations of data and procedures, or independent but interrelated
programs.
9
NAME: _______________________________________________________ DATE: _____________________________
10