Back to Random Number Generation In A Programming

Oak National Academy

Lessons written by expert teachers in England, each with slides, a video and quizzes.

Their topic:
Programming: iteration · Programming: strings and lists
For your topic:
Random Number Generation In A Programming · Computer Science - 9210

Use these lessons alongside our lesson note, which covers your syllabus in full.

What this covers in your syllabus

2 lessons from Oak National Academy

Lesson 1 of 2 · GCSE level, ages 14 to 16

Randomisation

By the end: I can import the random module into my code to produce random numbers.

Key learning points

  1. Be able to locate information using the language documentation.
  2. Import modules into your code.
  3. Demonstrate how to generate random numbers.

Keywords

module
a file with pre-made code you can use in your own programs
standard library
a collection of built-in modules that come with Python

A common mistake

Mistake: You have to write the full code for random number generation yourself.

In fact: Python's standard library includes the random module, which already has functions like randint() to generate random numbers. You just need to import it.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

Do you need to write all the code for random number generation yourself?
What is a module in Python?
What is the standard library in Python?
How do you import a module in Python?

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

Lesson 2 of 2 · GCSE level, ages 14 to 16

String manipulation

By the end: I can create a program using string handling techniques.

Key learning points

  1. The contents of a string can be validated.
  2. The random module can be used to generate random numbers and pick random letters from a string.
  3. Concatenation is a way of joining strings using the + operator to make a new string.
  4. Strings can be manipulated using the upper() and lower() string methods to convert the string into upper- or lowercase.

Keywords

random
a module that can generate random numbers, pick random items or shuffle a list
concatenation
the process of joining strings together to create a new string
lower()
a string method that converts all letters in a string to lowercase
upper()
a string method that converts all letters in a string to uppercase

A common mistake

Mistake: The random module will only generate random numbers.

In fact: The random module can generate random characters as well as numbers.

Check what you learned

From Oak National Academy's exit quiz. Choose every answer that is right.

What is the correct way to join the strings "blue" and "berry" into one word?
What must you include in your program to use the random library?
What will be printed by the following code? ```word = "Pinecone" print(word.upper())```
Which of the following correctly selects a random letter from the word "elephant"?
The random module generates ...

A computing lesson by Oak National Academy licensed under the Open Government Licence (OGL) v3.0. Read the licence

The wording comes from each publisher. The layout and the links to your syllabus are ours.