Single lesson · Written for OCR J277

Random numbers and programming practice – OCR GCSE Computer Science lesson (J277)

Pupils learn to use random number generation in a Python subprogram, test it, and handle a run-time error that could crash it.

Also in a bundle Cyber Security and Robust Programs – OCR GCSE Computer Science lessons (J277) 14 lessons for £39 · save 30% on buying separately

Lesson 13 of 14 in unit 11.1 Cyber Security and Robust Programs, taught in Year 11, Autumn 1. It answers one big question: How can a program pick a winner fairly by chance?

By the end, pupils can use random number generation in a Python subprogram, test it, and handle a run-time error that could crash it.

The Build (the main task)
Write a function pick_winner that is given a list of customer names and returns one chosen at random, then test it with three different lists, including one with a single name.
Support version
Part-filled function: the import and def lines are given, with gaps for the random index and the return.
Challenge
Make the program check for an empty list before picking, so it shows a message instead of crashing with a run-time error.
Real-world link
Kickstand runs a prize draw: one customer who ordered this month wins a free pair of trainers.
Key words
Random number generation, Run-time error and Unpredictable, each with a definition, an icon and a common mix-up on the key vocabulary slide.
Misconceptions it tackles
“random.randint(1, 10) can never give 10”; “A run-time error is caught before the program runs, like a syntax error”.
OCR J277 specification
2.2.3 (additional programming techniques: subprograms (procedures and functions), parameters and return values, local and global variables, and random number generation); 2.3.2 (testing: the purpose of testing, iterative and final testing, syntax and logic errors, normal, boundary, invalid and erroneous test data, and refining algorithms).

Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.

Pupils need computers for the main task.

Also sold in the Cyber Security and Robust Programs unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.

What's included

  • Slide deck (PowerPoint)
  • Lesson plan (Word)
  • Worksheet (Word)
  • Support worksheet with scaffolds (Word)
  • Random numbers and programming practice - Quiz Quiz Trade Cards
  • Single-teacher licence: use and adapt it with your own classes

More for GCSE Computer Science (OCR)

See all

Written for the specifications named. Not endorsed by or affiliated with any exam board.