Using libraries
About this lesson: Using libraries
In short
A library is a collection of ready-made, tested routines. Making random numbers yourself takes tricky code; a library does it in one line. Compare the two programs.

What you'll explore
- Libraries: Don't reinvent the wheel
- A library is a collection of ready-made, tested routines. Making random numbers yourself takes tricky code; a library does it in one line.
- Calling a function: Roll the dice
- import random loads the library; random.randint(1, 6) calls one of its functions and gives back a whole number from 1 to 6.
- In a game: A new question every time
- Games use random numbers so they are different every time. This maths room makes a new times-table question with two calls to randint.
- Check yourself: Which line?
- Sara wants her program to pick a random number from 1 to 100.
Also in this lesson
- Common mix-ups
- Python libraries to try
- A complete dice game
- Rock, paper, scissors
Words to know
- library
- A collection of ready-made, tested routines.
- module
- Python's name for a library file.
- import
- Load a library so its functions can be used.
- function
- A named routine that does a job and may give back a value.
- call
- Run a function.
Sources
- Python documentation: random module