L6 Lesson plan - Intro to Python programming - Y8
L6 Lesson plan - Intro to Python programming - Y8
Learning objectives
● Combine iteration and selection to control the flow of program execution
● Use Boolean variables as flags
Key vocabulary
Iteration, selection, conditions, Boolean (or logical) operators and expressions,
counting, flags
Preparation
Subject knowledge:
● You will need to be familiar with using a Python IDE.
● You will need to be able to locate and correct syntax errors in Python
programs.
● You will need to be comfortable with the use of arithmetic and relational
operators, and arithmetic and logical expressions (conditions).
● You will need to be comfortable with the use of selection and iteration in
Python programs.
● You will need to be aware of common misconceptions that you may
encounter with novice learners. See the common misconceptions in the
‘Notes on pedagogy’ section for a list of misconceptions relevant to this
lesson.
■ Worksheet
■ Python code: Task 1 starting point (ncce.io/py-lucky-60)
● A Python interpreter and IDE — we suggest using Mu (codewith.mu), or an
online environment such as Trinket.io.
● Assessment questions and answers — before the lesson, browse through
them, select the ones that you feel are most appropriate, and assemble
your summative assessment quiz.
Assessment opportunities
You can assess learners’ answers to the worksheets. In addition, you can assess
learners through observation, for example, by assessing how learners interact
through pair programming and collaborate to solve problems. At the end of the
lesson, learners will also take a summative assessment quiz.
At a glance
Starter Introduction
activity
Show the code for the number guessing game that learners
3 mins developed previously and discuss which of the labelled program
segments will need to be repeated.
Activity 1 Flags
7 mins Use live coding to introduce iteration in the program, while your
learners follow. Explain how Boolean variables can be used as ‘flags’
in our programs, to keep track of binary events.
20 mins Hand out the ‘Lucky number revisited’ worksheet, which picks up
from where the live coding activity left off. Ask learners to employ
pair programming to complete the tasks that guide learners through
Summary Reflection
5 mins
Ask learners to record and discuss their main takeaways from the
unit.
Outline plan
Please note that the slide deck labels the activities in the top right-hand corner
to help you navigate the lesson.
Starter Introduction
activity
(Slides 2–3) As learners enter the classroom, show on the board the number
guessing game that learners developed in Lesson 3. Identify and
3 mins label areas of distinct functionality in the code.
Point out that this is a simple version of the game, where the user
gets a single chance at guessing the number. Tell learners that, in
this lesson, they will extend the game, so that the user is
repeatedly asked to guess the lucky number.
The learners should identify the segments labelled “Ask the user to
guess” and “Display feedback to the user” as the ones that should
be repeated. Provide the answer (slide 3) and clarify why the
segment labelled “Pick a lucky number” should not be repeated: the
lucky number is only selected once, in the beginning of the program.
Activity 1 Flags
(Slides 5–7)
Start by pairing learners. They will work in pairs during this activity
7 mins and employ pair programming to complete the tasks in the next
activity. Remind learners of the driver and navigator roles and make
You will introduce iteration in the program along with your learners,
using live coding. Make sure that you ‘think aloud’, demonstrating
the thought process involved. Follow the steps below; slide 7 shows
the completed program.
Start the live coding session. Open the number guessing program
(ncce.io/py-lucky-6) and ask learners to do so too.
Indent the segments labelled “Ask the user to guess” and “Display
feedback to the user”, since they have been identified as the ones
that will need to be repeated. Discuss the role of indentation once
again. Demonstrate how to indent large segments of code in any
programming environment: select the code and press the Tab key.
Explain that Boolean variables like guessed are also called flags. As
in many real-life situations, flags can be used as indicators for an
event (e.g. the flag at Buckingham Palace). In this case, initially, the
flag is down, since guessed is initialised to False. The condition in
while checks the flag before each new round begins: the game will
only continue as long as the flag is down. However, the flag is never
raised, i.e. it is never set to True, so the game never terminates.
This is an issue that learners will address themselves at the start of
the next activity.
Note: It may seem odd that the value for lucky is not randomly
selected, like it was in Lesson 3. This will make testing the program
much easier for learners. Randomness will be introduced in the next
activity (as an explorer task).
Note: Using a Boolean variable is not the only way to program this
game. However, an examination of the alternative implementations
shows that this is probably the simplest approach for learners to
understand. Also, this is a pattern that comes in handy quite often,
especially when break is not to be used.
Task 4 — Final word: Display the lucky number if the user fails to
guess it.
selected.
Task 3 involves using the and operator. At the end of the activity,
you can use slide 9 to display the logical operators that can be used
in Python. This is meant to be used as a reference, so skim over the
slide, simply listing the available operators to convey an idea of the
sort of logical operations that can be performed.
Summary Reflection
(Slide 12)
Ask learners to use sticky notes to record their main takeaways from
Last 5 mins the unit. Ask them to write one thing that impressed them, one thing
that they learnt, and one thing that they didn’t particularly enjoy.
The latter might provide useful feedback for improving either the
content or the delivery of the unit.
Resources are updated regularly — the latest version is available at: ncce.io/tcc.
Attribution statement
This resource was created by Raspberry Pi Foundation and updated by STEM Learning for the
National Centre for Computing Education.
The contents of this resource are available for use under the Open Government License (OGL v3)
meaning you can copy, adapt, distribute and publish the information. You must acknowledge the
source of the Information in your product or application, by attributing Raspberry Pi Foundation and
STEM Learning as stated here and are asked to provide a link to the OGL v3.
The original version can be made available on request via [email protected].