0% found this document useful (0 votes)
30 views

L6 Lesson plan - Intro to Python programming - Y8

Uploaded by

22pereirag
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

L6 Lesson plan - Intro to Python programming - Y8

Uploaded by

22pereirag
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Year 8 – Intro to Python programming Lesson plan

Lesson 6 – Putting it all together

Lesson 6: Putting it all together


Introduction
In this final lesson of the unit, learners will apply and consolidate what they’ve
learnt by extending the number guessing game that they developed previously
into an iterative version that allows them multiple guesses.
They will then conclude the unit with a summative assessment quiz.

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.

You will need:


● Slides — note that some slides contain animations
● Activities:
○ Flags:
■ Python code: Live coding starting point (ncce.io/py-lucky-6)
○ Lucky number revisited:

Page 1 Last updated: 30-04-24


Year 8 – Intro to Python programming Lesson plan
Lesson 5 – Round and round

■ 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.

You may need:


● Additional Python code for the ‘Lucky number revisited’ activity:
○ Task 1: Ending the game — solution (ncce.io/py-lucky-61)
○ Task 2: Counting guesses — solution (ncce.io/py-lucky-62)
○ Task 3: Limiting guesses — solution (ncce.io/py-lucky-63)
○ Task 4: Final word — solution (ncce.io/py-lucky-64)
○ Explorer task: More information — solution (ncce.io/py-lucky-65)
○ Explorer task: Randomness — solution (ncce.io/py-lucky-66)
● Where do we go from here? A set of suggested projects that learners can
work on after finishing this unit, if they like
● Python cheat sheets

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.

Activity 2 Lucky number revisited

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

Page 2 Last updated: 30-04-24


Year 8 – Intro to Python programming Lesson plan
Lesson 5 – Round and round

building a number guessing game.

Assessme Summative assessment


nt
Ask learners to complete the summative assessment.
20 mins

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.

*Timings are rough guides

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.

Ask learners which of the labelled program segments will need to be


repeated and which will still be only executed once — you are
essentially asking them to think about which parts of the program
code will be included in the while block.

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

Page 3 Last updated: 30-04-24


Year 8 – Intro to Python programming Lesson plan
Lesson 5 – Round and round

sure that they alternate between roles (e.g. every 5 minutes, or


every time they move on from one task to the next).

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.

Live coding: Introducing iteration

Start the live coding session. Open the number guessing program
(ncce.io/py-lucky-6) and ask learners to do so too.

Insert a while statement (without a condition) before the segment


labelled “Ask the user to guess”.

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.

Live coding: Checking a Boolean flag

Explain to learners that the program will somehow need to keep


track of whether or not the user has guessed the number. This is
something that has either occurred or not, so you only need a
variable with two possible values. Such variables are called Boolean
and their value can be either True or False.

Introduce a Boolean variable called guessed into the program and


initialise it to False. A value of False for guessed will signify that the
user has not yet guessed the lucky number.

Ask learners what condition should be checked by the while


statement. The game should continue for as long as the value of
guessed is False, so the condition is guessed == False.

Run the program, and ask learners to do so too. They may


encounter syntax errors. Show slide 7 to help them check for
common errors and correct them.

When learners manage to run the program, it should become


apparent that the game never terminates, even when the user
guesses the number. Ask them why they think this is. Explain how to
terminate the program (depending on the development
environment, they may need to press a ‘Stop’ button or use the

Page 4 Last updated: 30-04-24


Year 8 – Intro to Python programming Lesson plan
Lesson 5 – Round and round

Control+C key combination).

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.

Activity 2 Lucky number revisited


(Slides 8–9)
Hand out the ‘Lucky number revisited’ worksheet, which picks up
20 mins from where the live coding activity left off. Here is a brief description
of the tasks, which essentially walk learners through building a
number guessing game:

Task 1 — Ending the game: Insert an assignment statement that


sets the guessed flag, so that the game ends when the user guesses
the number.

Task 2 — Counting guesses: Introduce a counter variable that


keeps track of the number of attempts that it takes the user to
guess the number. Refer to the worked examples if necessary.

Task 3 — Limiting guesses: Use the counter in the condition in


while to end the game when the user exceeds an allocated number
of guesses.

Task 4 — Final word: Display the lucky number if the user fails to
guess it.

Explorer task — Randomness: Have the lucky number randomly

Page 5 Last updated: 30-04-24


Year 8 – Intro to Python programming Lesson plan
Lesson 5 – Round and round

selected.

Explorer task — More information: Display additional feedback


to the user about whether the lucky number is larger or smaller than
their guess.

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.

Assessme Summative assessment


nt
(Slides 10– Select around 20 closed-form assessment questions from the ones
11) provided, making sure that they span the content of the entire unit.
Ask learners to answer them.
20 mins
If possible, it’s best to use an online tool for the quiz. These tools
provide instant visual summaries of learners’ answers to each
question, which will help you provide immediate whole-class
feedback, pinpoint any remaining misconceptions, and focus your
explanations.

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].

Page 6 Last updated: 30-04-24


Year 8 – Intro to Python programming Lesson plan
Lesson 5 – Round and round

Page 7 Last updated: 30-04-24

You might also like