Understand the term 'predefined function'
Identify and use appropriate predefined functions
At National 5 you looked at the following predefined function:
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))
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))
The length function is used to calculate the length of an array.
fib = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89] #Should print 10 print (len(fib))
The lower and upper functions turn a string to lowercase or uppercase.
x = "John" y = x.lower() z = x.upper() print(y) print(z)
In your jotter, write down an example of how each of the predefined function shown before could be used in Python