0% found this document useful (0 votes)
4 views3 pages

Teaching Ideas Lesson Five

This document outlines Lesson Five of an Introduction to Python series, focusing on using while-loops, validation, verification, and generating random numbers. It includes teaching ideas, starter activities, main activities, and a plenary to assess student understanding. The lesson aims to enhance programming skills and prepare students for further studies in computer science and upcoming assessments.

Uploaded by

Abdul Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Teaching Ideas Lesson Five

This document outlines Lesson Five of an Introduction to Python series, focusing on using while-loops, validation, verification, and generating random numbers. It includes teaching ideas, starter activities, main activities, and a plenary to assess student understanding. The lesson aims to enhance programming skills and prepare students for further studies in computer science and upcoming assessments.

Uploaded by

Abdul Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to Python 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.

Page 1 of 3 visit twinkl.com


Main Activities
Validating and Verifying
• This activity might seem like an interlude or diversion, but in fact is an important Computing topic. Issue Validating and
Verifying Activity Sheet.
• Validating data is checking that inputted data is in the correct format. There are several different types of validation check,
such as: presence checking (making sure that something has been entered), existence checking (making sure that data exists on
a database), length checking (making sure that the data is not too short or long), and format checking (making sure that data is
in the correct form). There are other types of validation such as range check (a value should fall between expected values) and
check digit (the last digits in a code – such as a barcode – are used in a special calculation to check that the other digits are all
correct). Validation is usually performed by a computer program.
• Verifying data is showing a user what they have already inputted, so that they can look at it and check (verify) that the inputted
data is as they expected it to be. Verification is usually performed by a person.
• Experience shows that students often get these latter two terms mixed up, so it is worth labouring over the differences between
them.
• The provided Python program Email.py is a very good example of both validation and verification in practice.

While You Wait


• Using the slides on the PowerPoint as a guide, explain to your students how the program Email.py works.
• Key points to refer to include: how variables are used to store information; the importance of indentation in Python; and the
use of empty strings.
• It is worth explaining that for-loops are also known as ‘count-controlled’ loops (when we want to repeat things a fixed number
of times), and while-loops are also known as ‘condition-controlled’. These are terms often used in GCSE Computer Science
specifications. Computer Scientists like to have lots of complicated sounded terms for the same thing, and further terms for
for-loops and while-loops are ‘definite’ and ‘indefinite’ iteration respectively.
• One final but significant point: the ‘condition’ of the while-loop (in this case: while email == “”: ) is at the beginning/start of the
loop, instead of at the end. This means that if the value of email is not empty to start with, then the code within the while-loop
may never actually execute. This is a finer-point and will be beyond some students, but it is something that is referred to at
GCSE level and beyond. (There is actually another type of loop called a repeat-until loop, where the condition is at the end).

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.

Page 2 of 3 visit twinkl.com


Knowledge Knockout
Refer to the previous Python file AskMonty.py which contains examples of lists, iteration (while-loops) and the random module.
Rather than asking students to create code to solve a problem (which many students find very difficult without having had years of
programming experience) the final challenge is to ask students to open Python file Quiz.py (tried and tested) and add annotation
to explain each section of code. This learning technique provides learners with a working solution and is accessible to all abilities
so that all students can enjoy some degree of success without frustration or failure. Issue Knowledge Knockout Activity Sheet.

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.

Page 3 of 3 visit twinkl.com

You might also like