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

Python Variable, Constant Worksheet

Uploaded by

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

Python Variable, Constant Worksheet

Uploaded by

keerthana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Variables and constants

Teacher’s Notes

Lesson Plan
Length 60 mins Specification Link 2.1.7/jk

Candidates should be able to:


(j) define the terms variable and constant as used in an imperative language and use
Learning objective
variables and constants
(k) identify and use variables, operators, inputs, outputs and assignments

Time (min) Activity Further Notes

5 Use the following discussion to explain what variables, E.g. First name, surname, school
constants and identifiers are. admission number, school year, tutor
• Ask the students how their teachers keep track of group, universal student number. (could
them and know who they are dealing with when have a list of these to show to the
checking homework, marking tests and exams, particular class)
writing reports, etc.
• These are their characteristics or properties, e.g.
First_Name = Fred
Surname = Smith
Age = 15
Year = 10
Tutor_Group = 10WA
• Fred, Smith, 15, 10, 10WA are values associated
with them and help to describe them.
• But without knowing that ‘15’ is their age or ‘10’ is
their year group they would be meaningless –
someone could incorrectly assume they were aged
10 and in year 15.
• So each of these values needs an identifier to say
what it is about.
• Ask the students which values will stay the same or first name, universal student number,
constant throughout their school career (surname could be iffy).
• Ask which will change or be variable throughout age, year group, tutor group.
their school career.
Explain to students that, when programming we often
need to keep track of the value of something, so we
create a variable to hold that value.
5 Watch the video, pausing to discuss the content.

5 Discuss the video to assess learning. Ask questions Answers:


such as:
• What is a variable? A quantity capable of assuming any of a
set of values.
• What is a constant? A quantity that never changes.
• What is an identifier A label or name representing a variable or
constant.

®
Time (min) Activity Further Notes

5 Explain that in programs you often have to keep track of


several values of different things. It is important therefore
to give each value a name to help us remember what it
does. This name is called an identifier.
Explain that identifiers should be long enough to easily
tell what they store, yet short enough to type easily and
not make code cumbersome.
Good identifiers:
• Keep them short (around 8–20 characters)
• Avoid over-abbreviation (e.g. counter not ctr, which
could mean centre, control, contrast or contract!)
• Be consistent! If you used dogX, be sure to use
dogY, not dog_y, yDog or dogsYCoord. However, if
you’re editing someone else’s code, be sure to follow
their naming conventions, even if they differ from your
usual style.
10 Worksheet 1
Students to complete Worksheet 1 either on paper or
on the computer. They may need access to the Internet
to research some of the questions.
Ask individual students for their answers and discuss
with the class so that all students will have the correct
answers.
10 The students use interactive Activity 1. You can use this opportunity to circulate
amongst the students and assess their
understanding; to support them if they are
struggling and extend them if they are of a
higher ability.
Extension Challenge/Homework Further exam style practice questions.
Students to complete and submit Worksheet 2 for
homework.
10 Homework The homework enables the students to
Students to write a short piece of code that asks for two further practise identifying variables,
numbers, adds them together and outputs the answer. constants and operators.

Plenary The plenary allows students to share their


In pairs, explain to your partner one thing that you have understanding with each other and solve
understood really well. Then ask them a question about each other’s’ queries. If there is time then
one thing you would like an answer to. Can you answer this can be extended so that if one
your partner’s question? partner is unable to answer the question
then the question is extended to other
groups or the whole class.

®
WORKSHEET 1 ANSWERS

1 Locate the variables, constants and operators in this Python code.


Underline constants with a straight line, variables with a zigzag underline and
circle the operators. Draw a box around the equals sign of any assignments.

®
WORKSHEET 2 ANSWERS

1 A program contains the following code to calculate the circumference of a bicycle


wheel, using the wheel size (diameter):

BEGIN CONSTANT Pi = 3.14


INPUT WheelSize
Circumference = Pi * WheelSize
OUTPUT Circumference
END
(a) (i) State the names of the constant and the variables. [2]

Constant: Pi

Variables: WheelSize, Circumference

(ii) Explain one difference between a constant and a variable. [2]

Constants are defined ONCE and never change, variables can hold different
values
throughout the execution of the program.

(b) The data type of WheelSize is integer and the data type of Circumference is real
number. Explain the difference between an integer and a real number. [2]

Integers are whole numbers, positive or negative (e.g. 7, –5, 0, 2345) whilst real (or
‘floating point’) numbers can have both an integer part and an optional decimal part
(e.g. –27.84, 0, 14.0, 1673.90, 0.413).

You might also like