Skip to content

Advanced Programming I – SS3 Digital Technologies Lesson Note (First Term)

Lesson note at a glance

Class
SS3
Subject
Digital Technologies
Term
First Term
Reading time
5 min
Start of this note, 1 of 7
Take this term’s notes offline
Reading here is free. Download all 7 SS3 Digital Technologies First term notes as PDF to print and Word to edit.
Download all three terms, ₦2,000
Instant download. Secure payment by Paystack. Card, bank transfer, USSD or OPay. Payment stuck? WhatsApp us.

A function is a named block of code that performs a specific task. An array, called a list in Python, is one object that holds many items in a specific order.

Behavioural objectives

By the end of the lesson, students should be able to:

Advertisement
  1. Define a function and give two reasons for using one.
  2. Identify the parameters, body and return value of a function.
  3. Explain what an array is, and describe elements and indices.
  4. Describe four common array operations: accessing, appending, inserting and traversing.
  5. Explain how a function can take an array as its input.

What is a function?

A function is a named block of code that performs a specific task, and it runs whenever we call its name.

Think of a chef. Every time a customer orders a “Special Omelette”, the chef must:

  1. Crack three eggs.
  2. Chop onions and peppers.
  3. Whisk with salt.
  4. Fry for 3 minutes.
  • The problem: explaining four steps to 50 customers is tiring and leads to mistakes.
  • The fix: write the recipe once and label it “MakeSpecialOmelette”.
  • Calling: whenever the omelette is needed, the chef uses that name.

Why do we use functions?

  • Reusability: write the code once and use it many times.
  • Organisation: the main program stays short and does not become a messy “spaghetti” bowl.
  • Fewer errors: a mistake is fixed in one place only.
  • Clean code: a descriptive name such as calculate_average lets anyone read your work.

What are the parts of a function?

A function has three parts: parameters, a body and a return value.

A function works like a small machine. You put something in, it does some work, and it gives something back.

Parameters (the inputs)

  • Meaning: the names listed in brackets after the function name, which receive the data.
  • Example: a calculator function needs two numbers as inputs.
  • Argument: the actual value given to the function when it is called.

The body (the process)

  • Meaning: the lines of code that carry out the task.
  • Example: the addition, subtraction or sorting happens here.
  • Python rule: the body is indented under the line that starts with def.
Advertisement

Return value (the output)

  • Meaning: the final result sent back to the main program.
  • Keyword: Python uses return to send the result back.

Example of a function in Python

def greet_student(name):
return “Hello ” + name + “, welcome to SS3!”

The second line is indented by four spaces because it is the body.

  • def: the keyword that creates (defines) a function.
  • greet_student: the name of the function.
  • name: the parameter, which is the input.
  • return line: the body, which builds the greeting and returns it.
  • Calling it: greet_student(“Ada”) returns “Hello Ada, welcome to SS3!”.

What is an array?

An array is a single object that holds many items in a specific order, and Python calls it a list.

Before arrays, we used variables. Think of an array as a bookshelf and a variable as a single box.

  • Variable: holds one item only.
  • The problem: 100 separate variables (student1, student2 and so on) are slow to write and easy to get wrong.
  • The fix: one array holds all 100 names.
Feature Variable Array (list)
Items held One Many
Picture A single box A bookshelf
Position numbers None Each item has an index
Python example name = “Ada” students = [“Ada”, “Bola”, “Chidi”, “Emeka”]

What are elements and indices?

  • Element: an actual item inside the array.
  • Index: the “address” or position number of an element.
  • The zero rule: counting starts at 0, not 1, so the first item is at index 0.
  • Last index: in an array of 4 items, the last index is 3.
students “Ada” “Bola” “Chidi” “Emeka” index 0 index 1 index 2 index 3
A Python list with four elements and their indices, based on standard computing texts.
Advertisement

What are the common operations on arrays?

There are four common array operations: accessing, appending, inserting and traversing.

Accessing

  • Meaning: looking up the item at a given position.
  • Example: students[2] gives “Chidi”.

Appending

  • Meaning: adding a new item to the very end of the list.
  • Example: students.append(“Funke”) adds “Funke” after “Emeka”.

Inserting

  • Meaning: putting an item into the middle, which pushes everything after it back by one place.
  • Example: students.insert(1, “Tunde”) puts “Tunde” at index 1, and “Bola” moves to index 2.

Traversing

  • Meaning: walking through the list from start to finish to visit every item.
  • Tool: a for loop is the usual way to traverse.

What is the difference between appending and inserting?

Appending adds at the end only. Inserting adds at any chosen index and shifts later items.

Point Appending Inserting
Position Always the end Any index you choose
Other items Do not move Items after it move back
Python append(item) insert(index, item)

How are loops used with arrays?

A for loop steps through the array one index at a time, so the same action is done to every element.

Example: give every student in the array an “A” grade.

  1. Create an empty list: grades = [].
  2. Start the loop: for student in students:
  3. In the loop body, add a grade for each student: grades.append(“A”).
  4. The loop ends after the last element, so every student has an “A”.

How are functions and arrays used together?

A function can take a whole array as its input, so one call can work on many values.

Scenario: you have an array of 10 exam scores and want the average.

  • The function: calculate_average(scores_list), where scores_list is the parameter.
  • Inside the function: it adds all the numbers in the array and divides by the count of items.
  • The result: it returns a single number, the average.
Advertisement

def calculate_average(scores_list):
total = sum(scores_list)
return total / len(scores_list)

  • sum(scores_list): adds every element in the list.
  • len(scores_list): gives the number of elements, which is 10 here.
  • return: sends the average back to the main program.

Evaluation

  1. What is a function? Give two reasons for using one.
  2. Name the three parts of a function and say what each one does.
  3. What is an array, and at which index is the first item?
  4. Explain the difference between appending and inserting.
  5. Describe how calculate_average(scores_list) finds the average of 10 exam scores.

Assignment

Choose a task you repeat often, such as making a meal. Give it a function name, then state its inputs, what happens in its body and what it returns. Then explain traversing an array, and say how a for loop can give every student in an array an “A” grade.

This term's Digital Technologies topics

SS3 First Term · 7 topics

  1. Advanced Programming I
  2. Advanced Programming II
  3. Software Development Lifecycle
  4. Networking II
  5. Cloud and Virtualization
  6. Internet of Things (IoT) Application
  7. Data Protection and Backup System
Advertisement

Lesson Notes for Other Classes

Print it or edit it in Word

Every note is free to read online. A PDF or Word copy of one subject costs ₦1,000 for one term, or ₦2,000 for all three terms.

Sign in first, then choose your class and subject at checkout.