Library routines

About this lesson: Library routines

In short

Languages include tested routines you can use straight away. Try each.

Library routines

What you'll explore

Ready-made routines: ROUND, RANDOM, MOD, DIV
Languages include tested routines you can use straight away. Try each.
Random numbers: Roll the dice
Random numbers make games unpredictable. Roll once, then 100 times.
String functions: Length and case
LENGTH, UCASE and LCASE are library routines too.
Why use libraries?: Don't reinvent the wheel
Library code is tested, fast and saves time. Compare writing your own with using a library.
Check yourself: MOD
What is 23 MOD 4?

Also in this lesson

  • Step by step
  • Watch out for these
  • More than the lesson
  • Stretch your brain
  • Try it yourself

Words to know

Library routine
A pre-written subroutine supplied with a language.
MOD
Remainder after division.
DIV
Whole-number division.
Random number
An unpredictable value.
Import
Load a library into a program.

Sources

  • Python documentation: random module
  • Python documentation: built-in functions
  • Raspberry Pi Foundation, Isaac Computer Science: library routines
  • BBC Bitesize, GCSE Computer Science: subroutines

An interactive lesson with a live experiment: move the sliders, press the buttons and answer quick questions. 5 short steps and a 8-question quiz. Part of the Family plan. Written and checked by Shalo Lab. Last updated 11 November 2026.

← Parameters, local and global variables · Two-dimensional arrays →

All lessons in Term 1 · Computing · Age 15