← Python

More Arithmetic

// performs integer (floor) division, % returns the remainder, and ** raises a number to a power

What it does: After importing math, you access its contents with math.pi or math.sqrt(). random.randint(1, 10) returns a random integer from 1 to 10 inclusive. import gives your program access to extra functions in an external module. Convention is to put all imports at the top so they're easy to find. randint includes both endpoints — could return 1, 2, 3, 4, 5, or 6. sleep() pauses program execution for the given number of seconds. Without 'import random', Python doesn't know what 'random' refers to. The dot . separates the module name from the function name.

Common mistakes: Module name is lowercase: import random, not import Random. Must use dot notation random.randint(), not just randint().

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What does import do?
Loads a module so you can use itPrints text
Matches
❌ randint(1, 6)
Error: Must import random first
Applying
Meanings
Term
import
Meaning
Keyword that loads a module so you can use its functions.
Practice
import random
Testing
Gaps
random
Check Answer
Spots
1import Random
2low = 1

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Spider' badge — Web Weaver, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What does import do?
A. Loads a module so you can use it ✓
B. Prints text
import gives your program access to extra functions in an external module
2. Where should import go in your code?
A. At the bottom
B. At the top of the file ✓
Convention is to put all imports at the top so they're easy to find
3. What does random.randint(1, 6) return?
A. A random number from 1 to 6 ✓
B. Always 1
randint includes both endpoints — could return 1, 2, 3, 4, 5, or 6
4. What does time.sleep(3) do?
A. Prints 3
B. Pauses for 3 seconds ✓
sleep() pauses program execution for the given number of seconds
5. What happens if you use random.randint() without import?
A. NameError ✓
B. Returns 0
Without 'import random', Python doesn't know what 'random' refers to

Match the Pairs

randint(1, 6) Error: Must import random first
import Random Error: Module names are lowercase
import math print(math.pi) Valid: Access math.pi
import random random.randint(1, 10) Ok: Random integer 1-10
import math print(math.sqrt(25)) Output: 5.0
import math print(math.floor(3.9)) Output: 3

Key Term

import
Keyword that loads a module so you can use its functions.~~Module

Fill in the Blanks

1. import random print(random.randint(1, 10))
2. import random print(random.randint(1, 6))
3. import time time.sleep(2)
4. import random print(random.choice(colors))
5. import time time.sleep(3)

Spot the Error

Question 1
A import Random
B low = 1
C high = 10
D result = Random.randint(low, high)
E print(result)
Line A — Module name is lowercase: import random, not import Random
Question 2
A import random
B low = 1
C high = 10
D result = randint(low, high)
E print(result)
Line D — Must use dot notation random.randint(), not just randint()
Question 3
A import random
B low = 1
C high = 10
D result = random.randint(low)
E print(result)
Line D — randint() needs two arguments: the start and end numbers
Question 4
A import time
B print('Starting...')
C time.sleep('3')
D print('3 seconds later...')
E print('Done!')
Line C — sleep() takes a number, not a string: use 3, not '3'
Question 5
A import random()
B low = 1
C high = 6
D result = random.randint(low, high)
E print('Dice roll:', result)
Line A — Don't use parentheses with import: just import random
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?