Slides badge

Predefined functions

Learning Intentions

  • Understand the term 'predefined function'

  • Identify and use appropriate predefined functions

Success Criteria

  • Be able to explain the term predefined function
  • 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.

fib = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
#Should print 10
print (len(fib))

lower and upper

  • 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

Task

Presentation Overview
Close
JB
National 5 Computer Science :: Software Design and Development :: Predefined Functions
© J Balfour
11:40 | 07-06-2023
Slideshow Outline
Save progress Show presenter mode Toggle whiteboard
Dark Mode Bold Text Accessibility
Random Number Generator Timer Binary & decimal converter Show Python editor Show Knox 90
Provide feedback Help
Login
Keywords
    Sections
      Binary conversion
      Denary to binary conversion
      Binary to denary conversion
      Feedback 👍
      Accessibility

      Apply a filter:

      ×
      All slide files