Library Routines (Cambridge (CIE) O Level Computer Science)
Revision Note
Written by: Robert Hampton
Reviewed by: James Woodhouse
Library Routines
What are library routines?
A library routine is reusable code that can be used throughout a program
The code has been made public through reusable modules or functions
Using library routines saves programmers time by using working code that has already been tested
Some examples of pre-existing libraries are:
Random
Round
Random
The random library is a library of code which allows users to make use of 'random' in their programs
Examples of random that are most common are:
Random choices
Random numbers
Random number generation is a programming concept that involves a computer generating a random number to be used within a program to add an element of unpredictability
Examples of where this concept could be used include:
Simulating the roll of a dice
Selecting a random question (from a numbered list)
National lottery
Cryptography
Concept | Pseudocode | Python |
---|---|---|
Random numbers |
|
|
Random choice |
|
Examples in Python
Random code |
---|
|
National lottery |
---|
|
Round
The round library is a library of code which allows users to round numerical values to a set amount of decimal places
An example of rounding is using REAL values and rounding to 2 decimal places
The round library can be written as:
ROUND(<identifier>, <places>)
Concept | Pseudocode | Python |
---|---|---|
Round |
|
|
Last updated:
You've read 0 of your 5 free revision notes this week
Sign up now. It’s free!
Did this page help you?