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

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 or the length of a string.

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 notes, write down an example of how each of the predefined function shown before could be used in Python

Task

Presentation Overview
Close
JB
Predefined Functions
© 2020 - 2024 J Balfour
18:59 | 16-06-2024
Join Live Session
Start Remote
Save Progress
Slideshow Outline
Presenter Mode
Generate Quiz
Generate Lesson Plan
Widget Screen
Canvas Controls
Random Selector
Timer
Volume Meter
Binary Converter
Python Editor
Show Knox 90
Provide Feedback
Help
!
Keywords
    DragonDocs Management
    Random selector
    Sections
      Binary conversion
      Denary to binary conversion
      Binary to denary conversion
      Feedback 👍
      Accessibility

      Apply a filter:

      ×
      Loading
      All slideshow files