Teaching Ideas Lesson Five
Teaching Ideas Lesson Five
Teaching Ideas
Learning Objective: To use a textual programming language to solve a variety of computational problems.
(From National Curriculum Computing programmes of study: key stage 3: subject content: statement 3.)
Success Criteria: • To know how to use while-loops in Python to iterate blocks of code.
• To understand the difference between validation and verification.
• To import the random module and generate random numbers.
Context: This is the fifth of a series of six lessons on the topic: Introduction to Python. Python is a popular
programming language and is easy to learn. Python can be downloaded from the main website.
It is recommended that you download Python version 3 (e.g. Python 3.6.4). Python 2 has a slightly
different syntax.
If local installation is not possible then there are many free online Python interpreters such as python3
and codeskulptor or py3.codeskulptor. Key terms and concepts are fully explained within the PowerPoint
resource which will be of particular use for non-specialist and cover teachers. Python Code Examples are
also included where appropriate. Within this lesson students will continue developing their programming
skills using Python IDLE. The key learning themes in this lesson are iteration using the while-loop in
Python, validation and verification, and generating random numbers. There are opportunities within
the learning Activities to work in groups and pairs with immediate feedback to formative and self-
assessment; such strategies are particularly effective in supporting PPI, EAL and SEND learners. Answers
to all of the Activity questions are provided. Additional Revision Activities are also included to help
students prepare for the Assessment in Lesson Pack 6. The knowledge and skills gained in this topic
will provide excellent preparation for further study with programming languages and problem solving.
The skills learned in this lesson will also provide invaluable preparation for non-examined-assessment
(NEA) and algorithms and programming topics at GCSE level Computer Science.
Starter
Are We There Yet?
The use of while-loops in Python is demonstrated in a fun way with this humorous starting activity. Students type the given code
into Python IDLE (from the PowerPoint slide and the Are We There Yet Activity Sheet) and run the program, or alternatively
you can provide them with a copy of the completed and tested file called Holiday.py. Providing learners with a completed program
is a good way to inspire and encourage, and may avoid some of the frustrations that some students have in copying lines of code.
However, for those who are typing in their own code, advice for how to spot and correct errors is provided on the proceeding
PowerPoint slides and it is worth reminding students that even the best programmers make regular mistakes with their code.
This program uses iteration to repeat a block of code again and again. In fact it will keep on repeating while the answer is ‘no’. As
an extension activity some students might want to experiment with the line: while answer == “no”: (e.g. change to while answer ==
“yes”: ) For further discussion, what if a user enters “No” or “NO”. Will the program still work as expected? A possible solution to
this: change code to while answer == “no” or answer == “No” or answer == “NO”:
The computing term for repeating something again and again is iteration. There are many situations in programming when we need
to repeat a section of code. Python has two special ways of repeating code: for-loops and while-loops. A while-loop will keep on
repeating while something is true. Last lesson we looked at the for-loop; today we’ll see how the while-loop works.
Really Random?
• Another diversion perhaps: “And Now for Something Completely Different” (which happens to be the title of a 1971 comedy
film based on the television comedy series Monty Python's Flying Circus!).
• Direct students to the website: https://www.random.org/
• Quotes from the website: “most random numbers used in computer programs are pseudo-random, which means they are
generated in a predictable fashion using a mathematical formula”; “surprising as it may seem, it is difficult to get a computer
to do something by chance. A computer follows its instructions blindly and is therefore completely predictable … As the word
‘pseudo’ suggests, pseudo-random numbers are not random in the way you might expect, at least not if you're used to dice rolls
or lottery tickets. Essentially, PRNGs are algorithms that use mathematical formulae or simply precalculated tables to produce
sequences of numbers that appear random.” (source: https://www.random.org/randomness/)
• This may provoke an interesting discussion on determinism and randomness.
• Using the Python file ReallyRandom.py demonstrate how to import the random module and generate a random integer
between two given values.
Plenary
Let’s Bring It All Together
At the conclusion of the lesson select individual students to tell you one new thing which they have learned today. To mix things
up a bit you could use a random name picker (there are many available online, this one is worth a look. Alternatively pick a student
and ask them to pick someone else to give the next answer. Try to avoid asking for hands-up; better to select those who would
benefit from being challenged.
As a prompt, ask students to give a definition for each of the key words: iteration, randomness, validation, verification (these
definitions can later be displayed on the final PowerPoint slides).
Rate Your Progress
Give students a few moments to look back at the learning objective and success criteria and reflect on their learning. For each
criteria they can rate their own progress using a traffic light system, whereby green light means that they feel fully confident with
this objective and understand it well; amber light means that they have understood most of the objective and are happy with their
progress; red light means that they have understood some of the objective and will think about it some more, perhaps asking a
friend or teacher for help later on.
Nailing It Down
We have learned a lot today about iteration (while-loops), validation and verification, and random numbers. In the next lesson
students will have an assessment to check their progress and learning. Use the Revision Activities to help them prepare for the
assessment. The following websites are also very helpful:
https://www.tutorialspoint.com/python3/index.htm
https://snakify.org/
https://trinket.io/features/python3
Homework
Issue the Homework Revision Guide for students to complete at home to help them prepare for the end of topic summative
assessment activity in Lesson Pack 6.