Tuesday, June 16, 2026

Programming with Python – Complete Study Guide 2026 Latest Updated for beginners

UNIT 9 – PYTHON PROGRAMMING (A/L ICT Sri Lanka)
Complete guide covering Introduction to Programming, Algorithms, Flowcharts, Python Fundamentals, Control Structures, Data Structures, Functions, File Handling, and Error Handling. This covers the core theory expected for Unit 9 and aligns perfectly with the Sri Lankan A/L ICT syllabus.
9.1 Introduction to Programming

Basic Definitions

  • Program: A set of instructions given to a computer to perform a task.
  • Programming: The process of writing, testing, debugging, and maintaining computer programs.

Why Programming? Automates tasks, solves problems efficiently, reduces human errors, and saves time.

Programming Languages

  • 1GL (Machine Language): Binary code (e.g., 10110011). Fast execution but difficult to understand and error-prone.
  • 2GL (Assembly Language): Uses mnemonics (e.g., MOV A,10). Requires an Assembler.
  • 3GL (High-Level Languages): Python, Java, C++, Pascal. Easy to read, easy debugging, and portable. (Python belongs to this category).

Language Translators

Feature Compiler (C, C++) Interpreter (Python)
Translation Whole program at once Line by line
Execution Speed Faster Slower
Object Code Generates object code No object code
Debugging Harder Easier
A/L Exam Question: Python uses which translator?
Answer: Interpreter.
9.2 Algorithms

Definition & Characteristics

An algorithm is a finite sequence of instructions for solving a problem.

  • Input: Accepts data (e.g., INPUT A).
  • Output: Produces result (e.g., PRINT SUM).
  • Definiteness: Every step must be clear.
  • Finiteness: Must end after finite steps.
  • Effectiveness: Each step must be practical.

Example: Add Two Numbers

START
INPUT A
INPUT B
SUM ← A + B
PRINT SUM
STOP

Control Structures

1. Sequence: Instructions executed one after another.

INPUT A, B
SUM = A + B
PRINT SUM

2. Selection: Decision making.

IF MARK >= 50 THEN
   PRINT PASS
ELSE
   PRINT FAIL
ENDIF

3. Iteration: Repeating instructions.

FOR I = 1 TO 5
   PRINT I
NEXT I
9.3 Flowcharts

Definition

A graphical representation of an algorithm using standard symbols.

Standard Symbols

Symbol Shape Purpose
OvalStart / Stop
RectangleProcess (Calculations)
ParallelogramInput / Output
DiamondDecision (Yes/No)
ArrowFlow Direction

Example: Find Area of Rectangle

START
  ↓
INPUT L, W
  ↓
AREA = L × W
  ↓
PRINT AREA
  ↓
STOP
9.4 Python Fundamentals

Features & First Program

Features: Simple syntax, Interpreted language, Open source, Cross-platform.

# First Python Program
print("Hello World")

Comments

# Single line comment

"""
Multi-line 
comment
"""

Variables & Naming Rules

Variables store data. Valid: student, student_name, age1. Invalid: 1age, student-name, class.

name = "Amal"
age = 18

Data Types

  • Integer: x = 10
  • Float: x = 10.5
  • String: name = "Kamal"
  • Boolean: status = True

Input and Output

# Input
name = input("Enter name:")
age = int(input())      # Integer input
salary = float(input()) # Float input

# Output
print(name)
Operators in Python

Arithmetic Operators

OperatorMeaning
+Add
-Subtract
*Multiply
/Divide
//Integer Division
%Modulus (Remainder)
**Power

Example: print(10 % 3) outputs 1.

Relational Operators

Operators: ==, !=, >, <, >=, <=

Example: 10 > 5 outputs True.

Logical Operators

Operators: and, or, not

Example: 5 > 2 and 4 < 8 outputs True.

Selection Statements & Loops

Selection (IF Statements)

# Simple IF
mark = 70
if mark >= 50:
    print("Pass")

# IF ELSE
mark = 45
if mark >= 50:
    print("Pass")
else:
    print("Fail")

# IF ELIF ELSE
mark = 80
if mark >= 75:
    print("A")
elif mark >= 65:
    print("B")
else:
    print("C")

Loops (Iteration)

# For Loop
for i in range(5):
    print(i) 
# Output: 0, 1, 2, 3, 4

# While Loop
i = 1
while i <= 5:
    print(i)
    i = i + 1
Data Structures: Strings & Lists

Strings

name = "Python"

# Indexing (Starts at 0)
print(name[0])  # Output: P

# Length
print(len(name)) # Output: 6

Lists

# Creating & Accessing
marks = [45, 67, 89]
print(marks[0])  # Output: 45

# Updating
marks[1] = 90

List Methods

  • marks.append(100) - Adds to the end
  • marks.insert(1, 50) - Inserts at index 1
  • marks.remove(67) - Removes value 67
  • marks.sort() - Sorts ascending
  • marks.reverse() - Reverses the list
Functions

Function Types

# 1. Without Parameters
def display():
    print("ICT")
display() # Calling the function

# 2. With Parameters
def add(a, b):
    print(a + b)

# 3. With Return Value
def add(a, b):
    return a + b
result = add(5, 10)
File Handling

Opening Files

f = open("data.txt", "r")  # Read Mode
f = open("data.txt", "w")  # Write Mode
f = open("data.txt", "a")  # Append Mode

Reading, Writing & Closing

# Write to file
f.write("Hello")

# Read from file
data = f.read()

# Always close the file
f.close()
Errors in Python
  • Syntax Error: Violates grammar rules.
    Example: if x > 5 (Missing colon at the end).
  • Runtime Error: Occurs during execution.
    Example: 10 / 0 (Division by zero).
  • Logical Error: Program runs but produces incorrect output.
    Example: Using area = length + width instead of area = length * width.
🌟 Frequently Asked A/L Questions

Q1: What are the three control structures?
Answer: 1. Sequence, 2. Selection, 3. Iteration.

Q2: Differentiate Compiler and Interpreter.

Compiler Interpreter
Whole program translatedLine by line
Faster executionSlower execution
Generates object codeNo object code

Q3: Write a Python program to find the largest of two numbers.

a = int(input())
b = int(input())

if a > b:
    print(a)
else:
    print(b)

Q4: Write a program to print numbers from 1 to 10.

for i in range(1, 11):
    print(i)

Q5: Create a list and print all values.

num = [10, 20, 30, 40]

for x in num:
    print(x)

🎓 Expert ICT, Coding, School Classes, Digital Marketing & University Project Guidance

Struggling with your university final year project? Want to master coding, upscale your business with expert digital marketing, or learn absolute computer basics from scratch? We offer high-quality individual and group online classes conducted in English, Sinhala, or Tamil mediums. Get guaranteed academic success and professional growth with tailored guidance.


🎓 University Final Year Project Guidance & AI

Get specialized, end-to-end mentoring and technical support to pass your degree or master's program with flying colors:

  • 🏫 Targeted Institutes: Expert guidance tailored for BIT UCSC, UoM, SLIIT, NIBM, and other leading universities.
  • 🔬 Postgraduate Support: Comprehensive assistance for MSc Software Final Year Projects.
  • 🤖 AI & Smart Applications: Step-by-step implementation of AI, Machine Learning (ML), and automation modules.
  • Guaranteed Success: Help with documentation, system architecture, coding, and viva preparation.

🏫 School ICT & Corporate Beginner Classes

  • 💻 Non-IT Staff Computer Basics: Absolute beginner-friendly online classes covering essential computer skills, office tools, and internet operations.
  • 🎒 Primary & Secondary (Grades 1-10): Interactive online ICT classes tailored to build strong foundations from early ages.
  • 📝 Exam Prep: Dedicated training packages for GCE O/L, GCE A/L ICT, and GIT exams.
  • 🌍 Global Syllabuses: Complete curriculum coverage for Local, Edexcel, and Cambridge in English & Tamil Mediums.

📢 Software Development & Digital Marketing Services

  • ⚙️ Software & Web Development: Professional custom software application and website development built using PHP & MySQL.
  • 🎯 Social Media Management: Content creation, publishing, and channel management for Facebook, Instagram, TikTok, and YouTube.
  • 📈 Ad Boosting: Highly targeted paid advertising campaigns to drive leads, traffic, and sales to your business.

📞 Connect With Us Instantly

Book your slot for online classes or get a premium tech service quote today!

💬 WhatsApp: +94 729622034

📧 Email: ITClassSL@gmail.com


🌐 Explore Our Resources & Communities

Stay updated with our latest tutorials, project ideas, and student guides across all our official platforms:

No comments:

Post a Comment