Computer Programming II SS2 Digital Technologies Lesson Note

Download Lesson Note
Lesson Notes

Topic: Computer Programming II

In our last lesson, we learned how to plan a program using Algorithms and Flowcharts. Now, it’s time to actually “speak” to the computer.

Since a computer doesn’t understand English directly (it only understands electricity—1s and 0s), we use a Programming Language like Python. It acts as a translator. You write something that looks like English, and Python converts it into something the computer can execute.

Why Python?

  • It is very easy to read.
  • It is used by big companies like Google, NASA, and Netflix.
  • You don’t need to be a math genius to start!

 

Your First Line of Code: The print() Function

The most basic thing a computer can do is talk back to you. In Python, we use the print() command.

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

Note: Anything inside the quotation marks “” is called a String. It tells the computer: “Just display this text exactly as it is; don’t try to calculate it!”

 

Variables: The “Storage Boxes”

Imagine you are moving house. You put your books in a box and write “BOOKS” on the outside. Later, when you need them, you just look for the box labeled “BOOKS.”

In programming, a Variable is a box in the computer’s memory where we store data. We give the box a name so we can find it later.

How to create a variable: user_name = “Chidi” age = 16

  • user_name is the label on the box.
  • “Chidi” is the item inside the box.

 

Data Types: What’s in the Box?

Not everything we store is the same. Python needs to know what kind of data is in the box so it knows how to handle it.

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

 

Basic Operators: Doing Math

Computers are basically giant calculators. Python uses symbols to perform math on our variables:

  • + (Addition): 5 + 2 is 7
  • (Subtraction): 5 – 2 is 3
  • * (Multiplication): 5 * 2 is 10
  • / (Division): 10 / 2 is 5.0
  • == (Comparison): Is x equal to y?

Important: In programming, one equals sign (=) is used to assign a value to a box. Two equals signs (==) are used to check if two things are the same.

 

Input: Asking the User

A good program isn’t just a one-way street. You want to ask the user for information. We use the input() command.

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

 

Summary Checklist

  • Python is our translator.
  • Variables are boxes that hold information.
  • Strings are for text; Integers are for numbers.
  • print() shows output; input() gets information.

 

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 favorite food.
  3. Task 2: Create two variables, num1 and num2. Give them values like 10 and 20. Create a third variable called result that adds them together and prints it.
  4. Task 3 (Challenge): Write a program that asks for a student’s name and their age, then prints: “Hello [Name], you will be [Age + 1] next year!”

Lesson Notes for Other Classes