More Arithmetic, online

Six activities your students do on their own devices. See who's finished, and their scores.

More Arithmetic in one minute

What students need to know

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.

Mistakes students make

  • Module name is lowercase: import random, not import Random.
  • Must use dot notation random.randint(), not just randint().
  • randint() needs two arguments: the start and end numbers.
  • sleep() takes a number, not a string: use 3, not '3'.
PREVIOUS · MODULE 17Imports
YOU ARE HERE · MODULE 18More Arithmetic
NEXT · MODULE 19While Loops

Discover other journeys with this module

What students will learn in this module

Every question in Module 18

Quick questions

  1. What does import do?ALoads a module so you can use itBPrints text
  2. Where should import go in your code?AAt the bottomBAt the top of the file
  3. What does random.randint(1, 6) return?AA random number from 1 to 6BAlways 1
  4. What does time.sleep(3) do?APauses for 3 secondsBPrints 3
  5. What happens if you use random.randint() without import?AReturns 0BNameError

Key terms

Students type the meaning of:

  • import
  • Module
  • random
  • time

Match the pairs

randint(1, 6)Match it to what it does
import RandomMatch it to what it does
import math
print(math.pi)
Match it to what it does
import random
random.randint(1, 10)
Match it to what it does
import math
print(math.sqrt(25))
Match it to what it does
import math
print(math.floor(3.9))
Match it to what it does

Fill in the blanks

  1. ______ random
    print(random.randint(1, 10))
  2. import random
    print(random._______(1, 6))
  3. import ____
    time.sleep(2)
  4. import random
    print(random.______(colors))
  5. import time
    time._____(3)

Spot the error

Question 1

Aimport RandomBlow = 1Chigh = 10Dresult = Random.randint(low, high)Eprint(result)

Question 2

Aimport randomBlow = 1Chigh = 10Dresult = randint(low, high)Eprint(result)

Question 3

Aimport randomBlow = 1Chigh = 10Dresult = random.randint(low)Eprint(result)

Question 4

Aimport timeBprint('Starting...')Ctime.sleep('3')Dprint('3 seconds later...')Eprint('Done!')

Question 5

Aimport random()Blow = 1Chigh = 6Dresult = random.randint(low, high)Eprint('Dice roll:', result)