Back to Random Number Generation In A Programming
N
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
1
Randomisation
2
String manipulation
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
Be able to locate information using the language documentation.
Import modules into your code.
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?
Yes, Python doesn’t have built-in functions.
Yes, it’s required for every program.
No, Python’s standard library includes the random module.
No, but you have to create your own module.
What is a module in Python?
a collection of built-in functions
a file with pre-made code you can use in your programs
a programming loop
a tool for drawing shapes
What is the standard library in Python?
a place to store user data
a tool to create loops automatically
a generator for random numbers
a collection of built-in modules that come with Python
How do you import a module in Python?
`use module()`
`include module_name`
`import module_name`
`add module_name()`
Check answers
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
The contents of a string can be validated.
The random module can be used to generate random numbers and pick random letters from a string.
Concatenation is a way of joining strings using the + operator to make a new string.
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?
`"blue" & "berry"`
`"blue" + "berry"`
`"blueberry".join()`
`"blueberry".concat()`
What must you include in your program to use the random library?
include random
import random
using random
from random
What will be printed by the following code? ```word = "Pinecone" print(word.upper())```
pinecone
PINECONE
PineCone
Pinecone
Which of the following correctly selects a random letter from the word "elephant"?
`random.pick("elephant")`
`random.shuffle("elephant")`
`random.choice("elephant")`
`random.letter("elephant")`
The random module generates ...
just random numbers
just random letters
any random character
Check answers
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.