L2 Lesson plan - Intro to Python programming - Y8
L2 Lesson plan - Intro to Python programming - Y8
The main activity in this lesson will require learners to construct their own short
programs for the first time, through scaffolded tasks.
Learning objectives
● Describe the semantics of assignment statements
● Use simple arithmetic expressions in assignment statements to calculate
values
● Receive input from the keyboard and convert it to a numerical value
Key vocabulary
Input, output, variables, operators, expressions, integer and string type,
execution, walk-through
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 output, input, and
assignment in Python, including arithmetic input.
● You will need to be comfortable with the use of arithmetic operators and
expressions.
Assessment opportunities
Multiple choice questions throughout the lesson provide a means for quick
formative assessment on specific concepts. You can also 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. The homework will also provide
an opportunity to assess whether the lesson objectives have been achieved.
Page 2
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
At a glance
Starter Make predictions
activity
Use three multiple choice questions on short code samples to help
10 mins learners recall some of the most important points from the previous
lesson and connect those points with ideas that will be introduced
in this lesson.
5 mins Pose and discuss two multiple choice questions that address
common misconceptions about assignment statements.
20 mins Hand out the ‘How to input numbers’ worksheet and ask learners to
apply what they have learnt in programming tasks that involve
7–8 mins per
task numerical input and arithmetic expressions.
4 mins
solutions
Page 3
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
Outline plan
Please note that the slide deck labels the activities in the top right-hand corner
to help you navigate the lesson.
The lines of code on slides 2 and 3 are identical, but they have
been swapped around. This will provide you with an opportunity to
emphasise how instructions are executed in order, and that a
variable needs to have been assigned a value before that value is
referenced.
Code fragment #3
The piece of code on slide 4 involves user input. This will allow you
to stress that the actual value of the user variable is not known
while the programmer is writing the program. That value is
determined by the user during program execution. However, the
programmer is still able to reference that unknown value in the
program, using the name of the variable.
Page 4
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
Program execution
Page 5
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
The slides also illustrate how to use sketching to keep track of the
values of variables.
Hand out the ‘Order matters’ worksheet and ask learners to carry
out the task, which is essentially a Parson’s Problem (to find out
more, see the ‘Notes on pedagogy’ section).
MCQ1: What will be the value of double, after executing line (A)?
number = 5
double = 2 * number
number = 15 line labelled (A)
MCQ2: What will be the value of number, after executing line (A)?
Page 6
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
number = 5
number = number + 10 line labelled (A)
In this activity, you will use live coding (to find out more, see the
‘Notes on pedagogy’ section) to guide learners to develop a simple
program that asks the user for their year of birth and calculates
their age. This will allow you to demonstrate how to develop a
solution using the constructs that they are familiar with, but also
manage their reactions when they realise that the program will not
function properly because the input received from the keyboard is
textual, while the input required by the program is numerical.
Pair learners, as they will be doing pair programming for the rest
of the lesson.
Inform learners that you will be making a program that asks the
user for their year of birth and calculates their age. Explain why
you need to use a variable to refer to the user’s year of birth and
ask how the program can receive user input.
print("Year of birth?")
birth_year = input()
Make sure that you demonstrate running the program to check that
everything works so far, even though it’s only two lines long.
Note: At this point, learners are not familiar with using the int
function to convert the string that input returns to a number. You
will introduce this later on in this activity. Therefore, for now, you
Page 7
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
will only use input, but you will expand on this later on.
print("Year of birth?")
birth_year = input()
age = 2020 - birth_year
print("You are", age, "years old")
Use int to convert the year of birth to an integer (slide 19) and
make sure that learners are also able to do this in their programs.
Stress that this is what they will need to do whenever they are
building any program that requires integer input.
Homework Assign the homework for this lesson. You could also include
questions from the assessment that learners will complete at the
end of the unit.
Page 8
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
Notes on pedagogy
Common misconceptions
Throughout these lessons, you should be aware of the common misconceptions
that may arise with novice programmers. The misconceptions below are a
selection from Appendix A of Juha Sorva’s PhD thesis, Visual Program Simulation
in Introductory Programming Education, and are relevant to this lesson. The list
will help you avoid using any examples or explanations that may give rise to
these misconceptions, and it will also help you spot them, should they arise with
your learners.
M1, 2, 7: The computer knows or is able to deduce the intention of the program
or of a piece of code, and acts accordingly. The machine understands English.
M6: Difficulties with telling apart the static and dynamic aspects of programs.
M155: Numbers are just numbers. (Why have int and float separately?)
M9: A variable can hold multiple values at a time / ‘remembers’ old values.
M158, 159: Confusion between data in memory and data on screen. The
computer keeps what has been printed in memory (as part of state?).
Parson’s Problems
The online course Programming Pedagogy in Secondary Schools by the
Raspberry Pi Foundation describes Parson’s Problems as “a task that involves
giving learners all of the lines of code required to solve a problem, but with the
lines jumbled so that they are not in the correct order. Learners are required to
place the lines into the correct order to form a working code segment. The main
benefit of Parson’s Problems is that the learner is focusing on code structure
rather than syntax. The process lowers the cognitive load, allowing learners to
Page 9
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
Live coding
Greg Wilson, in his book Teaching Tech Together, describes live coding as
follows: “the teacher writes code in front of the class while the learners follow
along, typing it in and running it as they go”. He calls it “the most effective way
to teach programming” and goes on to list advantages and cite relevant
research.
Worked examples
The worksheets handed out to learners throughout this unit will often start with a
worked example, i.e. an annotated solution to a problem. The tasks that follow
the worked example will be closely linked to it, so that learners can use it as a
reference point. These worked examples will also have been presented in class,
using live coding, so the reasoning behind the solution will have been fully
explained to learners.
Worked examples reduce cognitive load and can help learners assimilate new
information. You can find out more about them in the resources referenced at
the end of the lesson plan.
A lot of the multiple choice questions used within the lessons are targeted at
specific misconceptions, which are outlined in the lesson plan. The same applies
for the questions suggested for assessment, with the rationale behind the
questions explained in the accompanying solutions.
Page 10
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
The notion of ‘sketching’ variables and their values is referenced in the lesson
slides. This links to the idea of using drawings to illustrate how program state
(e.g. the values of variables, and the contents of data structures) is modified
during program execution. This can provide a visual alternative to trace tables
that may be less cumbersome for learners at this stage.
Notional machine
The three dimensions are: text surface, program execution, and function
(purpose). In these lessons, especially while tracing through a program being
executed, you will link these three dimensions by describing how a static
program turns into a dynamic process when executed, along with the purpose of
execution, i.e. what the instructions of the program aim to achieve.
Additional sources
● Pedagogy Quick Read: Live coding
● Pedagogy Quick Read: Worked examples
● Pedagogy Quick Read: Peer instruction
● Programming Pedagogy in Secondary Schools: Inspiring Computing
Teaching on FutureLearn, which contains sections on Parson’s Problems,
worked examples, and live coding
Page 11
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
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 12
Year 8 – Intro to Python programming Lesson plan
Lesson 2 - Crunching numbers
Page 13