Be able to identify and describe the predefined functions specified at National 5 level
Predefined functions
A pre-defined function carries out an operation or calculation using the data we give (pass) it and returns a single value. The functions listed below are relevant to the course content for National 5:
Round
Length
Random
The SQA sometimes refers to built-in object functions as predefined functions, when in actual fact they are not. If you want to find out more about this, look up object methods in Python.
An example: the YASS language
National 5
At National 5 you looked at the following predefined function:
Random
Round
Length
Random
The random predefined function generates a random number between a range in Python:
import random
#Generates a number between 10 and 100
print(random.randint(10, 100))
Round
The round function rounds a number to a specified number of decimal places.
x = 3.145
#Will give us 3.15
print(round(x, 2))
#Will give us 3.0
print(round(x, 0))
Length
The length function is used to calculate the length of an array.