Module 1: Programming Fundamentals, Algorithms & Flowcharts
Learn what programming is, how programming languages evolved, how to solve problems, design algorithms, write pseudocode, draw flowcharts, and convert logic into code.
Logically
Algorithms
Flowcharts
to Code
1.1 Module Overview
This module introduces the foundation of programming. Before learners write full Python programs, they must understand how to think like a programmer. Programming is not only typing commands; it is a structured way of analyzing problems, designing logical steps, and converting those steps into working code.
The module covers the meaning of programming, the evolution of programming languages, types of programming languages, compiled and interpreted languages, problem-solving techniques, algorithm design, pseudocode, flowchart symbols, decision and iteration flowcharts, and converting flowcharts into Python code.
1.2 Learning Objectives
- Define programming and explain its importance in modern digital industries.
- Describe the history and evolution of programming languages.
- Identify different types of programming languages and their uses.
- Differentiate between compiled and interpreted languages.
- Apply problem-solving techniques before writing code.
- Design algorithms using step-by-step logical instructions.
- Write clear pseudocode for simple problems.
- Use common flowchart symbols correctly.
- Create decision and iteration flowcharts.
- Convert flowcharts into simple Python programs.
1.3 What is Programming?
Programming is the process of writing instructions that tell a computer what to do. These instructions are written using a programming language such as Python, Java, C++, JavaScript, or C#.
A computer cannot guess what a user wants. It follows instructions exactly. Therefore, a programmer must write instructions clearly, logically, and in the correct sequence.
| Human Activity | Programming Concept | Example |
|---|---|---|
| Calculate salary | Arithmetic operations | salary = basic + allowance |
| Check pass or fail | Decision making | if marks >= 50 |
| Repeat attendance checking | Looping | for student in class_list |
| Store student records | Data structures | student = {"name":"Amin"} |
| Read report from file | File handling | open("report.txt") |
1.4 Why Programming is Important
Automation
Programming reduces repetitive manual work and increases productivity.
Problem Solving
It trains learners to think logically and break complex problems into smaller steps.
Digital Careers
Programming supports careers in AI, cyber security, data science, automation, software, and web development.
Innovation
It enables learners to create tools, apps, websites, systems, and business solutions.
1.5 History and Evolution of Programming Languages
Programming languages have evolved from machine-level instructions to modern high-level languages that are easier for humans to understand.
| Generation | Language Type | Description | Example |
|---|---|---|---|
| 1st Generation | Machine Language | Uses binary numbers 0 and 1. Very difficult for humans. | 10110000 |
| 2nd Generation | Assembly Language | Uses short symbolic instructions close to hardware. | MOV, ADD, SUB |
| 3rd Generation | High-Level Languages | Human-readable languages for general programming. | C, C++, Java, Python |
| 4th Generation | Problem-Oriented Languages | Designed for specific business or data tasks. | SQL, MATLAB |
| 5th Generation | AI and Logic-Based Languages | Used for artificial intelligence and logic programming. | Prolog, AI platforms |
Evolution Timeline
1.6 Types of Programming Languages
| Type | Description | Examples | Common Use |
|---|---|---|---|
| Low-Level Languages | Close to machine hardware. | Machine Language, Assembly | Hardware control, embedded systems |
| High-Level Languages | Human-readable and easier to write. | Python, Java, C++ | Applications, AI, systems |
| Scripting Languages | Used for automation and quick tasks. | Python, JavaScript, Bash | Automation, web, cyber security |
| Markup Languages | Used to structure content, not full programming logic. | HTML, XML | Web pages, documents |
| Query Languages | Used to manage and retrieve data. | SQL | Databases, analytics |
| Object-Oriented Languages | Organize code using classes and objects. | Java, Python, C# | Large applications |
1.7 Compiled vs Interpreted Languages
Programming languages can be executed in different ways. Some are compiled before execution, while others are interpreted line by line.
| Compiled Language | Interpreted Language |
|---|---|
| The whole program is converted into machine code before running. | The program is executed line by line by an interpreter. |
| Usually faster after compilation. | Usually easier for learning, testing, and debugging. |
| Compilation errors must be fixed before execution. | Errors may appear while the program is running. |
| Examples: C, C++, Go, Rust | Examples: Python, JavaScript, PHP |
Python as an Interpreted Language
Python is commonly used as an interpreted language. Learners can write a line of code and run it quickly, which makes Python suitable for beginners.
print("Python runs this line using an interpreter")Python runs this line using an interpreter
1.8 Problem Solving Techniques
Good programming begins before coding. A programmer must first understand the problem clearly, identify inputs, decide the processing steps, and define the expected output.
IPO Model
| Stage | Question | Example |
|---|---|---|
| Input | What data is needed? | Marks, price, quantity, age |
| Process | What calculation or decision is required? | Total = price × quantity |
| Output | What result should be displayed? | Total price, pass/fail result |
Problem-Solving Steps
- Understand the problem statement.
- Identify the required input.
- Identify the expected output.
- Break the problem into smaller tasks.
- Design an algorithm.
- Write pseudocode or draw a flowchart.
- Convert the logic into code.
- Test with sample data.
1.9 Algorithm Design
An algorithm is a step-by-step procedure to solve a problem. It must be clear, finite, logical, and produce a result.
Characteristics of a Good Algorithm
- Clear: Each step should be easy to understand.
- Finite: It must end after a number of steps.
- Input: It may accept data for processing.
- Output: It must produce a result.
- Effective: Each step must be practical and executable.
Example Algorithm: Calculate Total Price
- Start
- Input quantity
- Input price per item
- Calculate total = quantity × price per item
- Display total
- End
Example Algorithm: Check Pass or Fail
- Start
- Input marks
- If marks are greater than or equal to 50, display “Pass”
- Otherwise, display “Fail”
- End
1.10 Writing Pseudocode
Pseudocode is a simple English-like way of writing program logic. It is not written in exact programming syntax, but it helps programmers plan before coding.
Why Use Pseudocode?
- It helps learners focus on logic instead of syntax.
- It is easier to understand than actual code.
- It can be converted into any programming language.
- It helps detect missing steps before coding.
Pseudocode Example: Total Price
START INPUT quantity INPUT price total = quantity * price DISPLAY total END
Pseudocode Example: Pass or Fail
START
INPUT marks
IF marks >= 50 THEN
DISPLAY "Pass"
ELSE
DISPLAY "Fail"
END IF
ENDPseudocode Example: Repeat 5 Times
START
FOR counter FROM 1 TO 5
DISPLAY "Welcome to PDTC"
END FOR
END1.11 Flowchart Symbols
A flowchart is a visual diagram that represents the steps of an algorithm. It uses standard symbols to show start/end, input/output, processing, decisions, and flow direction.
Terminator
Shows where the process starts or ends.
Input / Output
Shows data entry or result display.
Process
Shows calculation or action.
Decision
Shows yes/no or true/false decision.
Flow Direction
Arrows are used to show the direction of movement from one step to another in a flowchart.
1.12 Decision Flowcharts
A decision flowchart is used when the program must choose between two or more paths. It commonly uses IF, IF-ELSE, or IF-ELIF-ELSE logic.
Example: Pass or Fail Decision
┌─────────┐
│ Start │
└────┬────┘
↓
┌──────────────┐
│ Input Marks │
└────┬─────────┘
↓
◇ Marks >= 50? ◇
/ \
Yes No
↓ ↓
┌──────┐ ┌──────┐
│Pass │ │Fail │
└──┬───┘ └──┬───┘
↓ ↓
└──────→ End ←──┘
Equivalent Python Code
marks = 65
if marks >= 50:
print("Pass")
else:
print("Fail")1.13 Iteration Flowcharts
Iteration means repetition. An iteration flowchart is used when the program needs to repeat a task multiple times using loops.
Example: Display Numbers 1 to 5
┌─────────┐
│ Start │
└────┬────┘
↓
┌──────────────┐
│ counter = 1 │
└────┬─────────┘
↓
◇ counter <= 5? ◇
/ \
Yes No
↓ ↓
┌──────────────┐ ┌─────┐
│Display count │ │ End │
└────┬─────────┘ └─────┘
↓
┌──────────────┐
│counter += 1 │
└────┬─────────┘
└──── back to decision
Equivalent Python Code
counter = 1
while counter <= 5:
print(counter)
counter = counter + 11
2
3
4
5
1.14 Converting Flowcharts to Code
To convert a flowchart into code, read each symbol in sequence and translate it into a programming statement.
| Flowchart Symbol | Programming Code Equivalent | Python Example |
|---|---|---|
| Start / End | Program begins or ends | # Start of program |
| Input | Use input statement | name = input("Enter name: ") |
| Process | Use calculation or assignment | total = price * quantity |
| Decision | Use if / else | if marks >= 50: |
| Iteration | Use for or while loop | while counter <= 5: |
| Output | Use print statement | print(total) |
Full Example: Calculate Training Fee
Problem: Calculate total fee for a course based on number of participants and fee per participant.
Pseudocode
START INPUT participants INPUT fee_per_participant total_fee = participants * fee_per_participant DISPLAY total_fee END
Python Code
participants = int(input("Enter number of participants: "))
fee_per_participant = float(input("Enter fee per participant: "))
total_fee = participants * fee_per_participant
print("Total Fee: RM", total_fee)Sample Output
Enter fee per participant: 250
Total Fee: RM 2500.0
1.15 Practical Activities
Activity 1: Daily Life Algorithm
Write an algorithm for one daily activity such as making tea, registering for a course, or withdrawing money from an ATM.
Activity 2: Pseudocode Practice
Write pseudocode to calculate the average marks of three subjects.
Activity 3: Decision Flowchart
Draw a flowchart to check whether a number is positive or negative.
Activity 4: Iteration Flowchart
Draw a flowchart to display numbers from 1 to 10.
Mini Project
Create an algorithm, pseudocode, flowchart, and Python code for a simple student grading system.
1.16 Interactive Final Assessment Quiz
Each correct answer gives +1 mark. Each wrong answer gives -0.5 mark.
1. Programming means writing instructions for a computer.
2. Which language generation uses binary instructions?
3. Python is commonly considered an interpreted language.
4. A flowchart decision symbol is usually represented by:
5. Pseudocode must follow exact Python syntax.
6. IPO stands for Input, Process, Output.
7. Iteration means repetition.
8. Which Python statement is used to display output?
9. An algorithm should be clear, finite, and logical.
10. The rectangle symbol in a flowchart normally represents a process.
Your Score: 0
1.17 Module Summary
This module introduced programming, programming language evolution, types of languages, compiled versus interpreted execution, problem-solving techniques, algorithm design, pseudocode, flowchart symbols, decision and iteration flowcharts, and converting flowcharts into Python code.