Skip to content

Computer Programming II – SS2 Digital Technologies Lesson Note (Second Term)

Lesson note at a glance

Class
SS2
Subject
Digital Technologies
Term
Second Term
Reading time
5 min
Start of this note, 2 of 8
Take this term’s notes offline
Reading here is free. Download all 8 SS2 Digital Technologies Second 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.

Python is a programming language that lets us write English-like instructions and have the computer carry them out. The computer only understands 1s and 0s, so Python acts as the translator.

Behavioural objectives

  1. Explain why Python is used as a programming language.
  2. Use the print() function to display text and results.
  3. Create variables and give them values.
  4. Identify the string, integer, float and Boolean data types.
  5. Use basic operators, and state the difference between = and ==.
  6. Use the input() function to ask the user for information.
Advertisement

What is a programming language?

A programming language is a set of words and symbols used to give instructions to a computer.

  • Machine language: the computer only understands electrical signals, written as 1s and 0s.
  • Translator: a language like Python converts our English-like code into something the computer can execute.
  • Link to the last lesson: we planned programs with algorithms and flowcharts. Now we write the code.

Why is Python used?

  • Easy to read: the code looks close to plain English.
  • Wide use: companies such as Google, NASA and Netflix use it.
  • Easy to start: a beginner does not need advanced maths.

How do you display output with print()?

The print() function displays text or results on the screen.

Example:
print(“Hello, SS2 Students!”)

  • Function name: print is written in lowercase.
  • Brackets: the item to display goes inside ( ).
  • Quotation marks: text inside “” is a string. Python displays it exactly as written.
  • Numbers and sums: print(5 + 2) shows 7, but print(“5 + 2”) shows 5 + 2.

What is a variable?

A variable is a named place in the computer’s memory where data is stored.

  • Box example: you put books in a box and write “BOOKS” on it. The label helps you find the box later.
  • Name: the label on the box.
  • Value: the item inside the box.

Example:
user_name = “Chidi”
age = 16

  • user_name: the label on the box. “Chidi” is the item inside.
  • age: the label on another box. 16 is the item inside.

What are the rules for naming a variable?

  • No spaces: use an underscore, as in user_name.
  • No number first: name1 is allowed, but 1name is not.
  • Case matters: Age and age are two different variables.
  • Meaningful names: choose names that describe the data, such as age or result.
Advertisement

What are data types?

A data type tells Python what kind of data is stored in a variable. There are four basic data types: string, integer, float and Boolean.

Data type What it is Example
String (str) Text or characters (always in quotes). “Lagos”, “Apple123”
Integer (int) Whole numbers (no decimals). 5, -10, 1000
Float Decimal numbers. 15.5, 0.75
Boolean (bool) True or False values. True, False
  • Quotes matter: “16” is a string, but 16 is an integer.
  • Boolean spelling: True and False start with a capital letter and have no quotes.
  • Checking a type: type(age) tells you the data type of age.

What are the basic operators?

An operator is a symbol that tells Python to perform an action on values or variables.

Arithmetic operators

Symbol Operation Example Result
+ Addition 5 + 2 7
– Subtraction 5 – 2 3
* Multiplication 5 * 2 10
/ Division 10 / 2 5.0
** Power 2 ** 3 8
// Whole-number division 7 // 2 3
% Remainder 7 % 2 1
  • Division answer: / always gives a float, so 10 / 2 is 5.0.
  • Joining text: + joins two strings, so “Good” + “day” gives “Goodday”.

Comparison operators

  • ==: is the left side equal to the right side?
  • !=: is the left side not equal to the right side?
  • > and <: is the left side greater than, or less than, the right side?
  • Result: a comparison always gives True or False, for example 5 > 3 is True.

What is the difference between = and ==?

  • Single equals sign (=): the assignment operator. It puts a value into a variable.
  • Double equals sign (==): the comparison operator. It checks whether two things are the same.
Point = ==
Job Assigns a value Checks equality
Example age = 16 age == 16
Result age now holds 16 True or False
Advertisement

How do you get input from the user?

The input() function shows a message, waits for the user to type, and returns what was typed.

Example:
name = input(“What is your name? “)
print(“Welcome to the class, ” + name)

  1. Python displays the message “What is your name? “.
  2. The user types a reply and presses Enter.
  3. Python stores the reply in the variable name.
  4. print() displays the welcome message with the name.

Why must you convert input before using it in sums?

  • Input is always a string: even if the user types 16, Python stores “16” as text.
  • int(): changes a string into an integer, so sums become possible.
  • str(): changes a number into a string, so it can be joined to text with +.

Example:
age = int(input(“How old are you? “))
print(“Next year you will be ” + str(age + 1))

What are common beginner errors?

  • SyntaxError: a rule is broken, such as a missing quotation mark or bracket.
  • NameError: a variable name is misspelt or used before it was created.
  • TypeError: a string and a number are joined with +, such as “Age: ” + 16.

Class lab activity

  1. Open the Python IDLE (the program where we type code).
  2. Task 1: Write a program that prints your name and your favourite food.
  3. Task 2: Create two variables, num1 and num2, with values such as 10 and 20. Create a third variable called result that adds them and prints it.
  4. Task 3 (Challenge): Write a program that asks for a student’s name and age, then prints: “Hello [Name], you will be [Age + 1] next year!” Use int() to convert the age and str() to join it to the text.

Evaluation

  1. Why do we need a programming language like Python to communicate with a computer?
  2. What is a variable? Using the box example, explain what the name and the value stand for.
  3. Name the four data types in the lesson and give one example of each.
  4. What is the difference between = and == in Python?
  5. State the job of print() and the job of input().

Assignment

  1. Write a Python program that stores your name in a variable called user_name and your age in a variable called age. Print your name, then print your age plus 5. Add a comment line naming the data type of each variable, and write one example each of a string, an integer, a float and a Boolean value.

This term's Digital Technologies topics

SS2 Second Term · 8 topics

  1. Computer Programming I
  2. Computer Programming II
  3. Programming Basics
  4. Control Structure
  5. Data Science Basics
  6. Big Data and Analytics
  7. Artificial Intelligence
  8. Machine Learning Basics
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.