- Explain what a program, an algorithm and a programming language are.
- Represent a solution using a flowchart and pseudocode.
- Distinguish a compiler from an interpreter and know how Python runs code.
- Identify syntax, runtime and logical errors.
What is Programming?
- A program is a set of step-by-step instructions that tells a computer what to do.
- Programming is the process of designing those instructions and writing them in a programming language that a computer can execute.
- Every program follows the basic Input → Process → Output model: it takes data in, works on it, and produces a result.
- Programming languages range from low-level (machine code, assembly – close to the hardware) to high-level (Python, Java, C++ – close to human language). High-level languages are easier to read, write and maintain.
Algorithm
A good algorithm has these properties:
- Input – zero or more values are supplied.
- Output – at least one result is produced.
- Definiteness – every step is clear and unambiguous.
- Finiteness – it always stops after a finite number of steps.
- Effectiveness – every step is simple enough to be carried out.
Example – algorithm to find the larger of two numbers
- Start.
- Read two numbers A and B.
- If A > B, display A; otherwise display B.
- Stop.
Flowchart
A flowchart is a diagram that shows the steps of an algorithm using standard symbols connected by arrows.
| Symbol | Name | Used for |
|---|---|---|
| Oval (rounded rectangle) | Terminal | Start and Stop |
| Parallelogram | Input / Output | Reading data or displaying results |
| Rectangle | Process | Calculations and assignments |
| Diamond | Decision | A Yes/No (True/False) condition |
| Arrow | Flow line | Direction of flow |
| Small circle | Connector | Joining parts of a long flowchart |
Pseudocode
Pseudocode describes an algorithm in plain, structured English that looks like code but follows no strict syntax. It helps you plan logic before writing real code.
BEGIN
READ A, B
IF A > B THEN
PRINT A
ELSE
PRINT B
END IF
END
The same logic in Python:
a = 25
b = 17
if a > b:
print(a)
else:
print(b)25
Compiler vs Interpreter
| Basis | Compiler | Interpreter |
|---|---|---|
| Working | Translates the whole program into machine code before running it. | Translates and executes the program statement by statement. |
| Output file | Produces a separate executable file. | Usually no separate executable. |
| Error reporting | Reports errors after analysing the whole program. | Stops at the first error it reaches while running. |
| Speed | Compiled program usually runs faster. | Usually slower to run, but quicker to test changes. |
| Examples | C, C++ | Python, JavaScript (commonly) |
Types of Errors
| Error | Meaning | Python example |
|---|---|---|
| Syntax error | The code breaks the grammar rules of the language; the program does not start. | print("Hi" (missing bracket) |
| Runtime error (exception) | The code is valid but fails while running. | 10 / 0 → ZeroDivisionError |
| Logical error | The program runs but gives a wrong result because the logic is wrong. | Using + instead of * to find an area |
try:
result = 10 / 0
except ZeroDivisionError as e:
print("Runtime error:", e)Runtime error: division by zero
Key Takeaways
- Plan before coding: algorithm → flowchart or pseudocode → program.
- Python compiles source to bytecode and interprets it; it is generally called an interpreted language.
- Syntax errors stop a program from starting, runtime errors stop it while running, and logical errors give wrong answers.
Video : Prerequisite : Programming Basics
Question / Answer (15 questions)
MCQ Test : Check Your Understanding (5 questions)
Select an option and press Check Answer, or answer all questions and press Submit Test to see your score. Each answer comes with an explanation.
Bibliography/References
The notes, questions and MCQs on this page are original explanations written for this course. The works listed below were consulted and are cited for attribution and further reading. Product names, logos and trademarks belong to their respective owners. Short quotations, where used, are marked and attributed.
- Python Software Foundation. (n.d.). General Python FAQ. Python 3 Documentation. https://docs.python.org/3/faq/general.html
- Python Software Foundation. (n.d.). Glossary. Python 3 Documentation. https://docs.python.org/3/glossary.html
- Python Software Foundation. (n.d.). Errors and Exceptions. In The Python Tutorial. https://docs.python.org/3/tutorial/errors.html
- International Organization for Standardization. (1985). ISO 5807: Information processing – Documentation symbols and conventions for data, program and system flowcharts. https://www.iso.org/standard/11955.html
- Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2022). Introduction to Algorithms (4th ed.). MIT Press.
- Aho, A. V., Lam, M. S., Sethi, R., & Ullman, J. D. (2006). Compilers: Principles, Techniques, and Tools (2nd ed.). Pearson.
- Downey, A. B. (2024). Think Python (3rd ed.). O’Reilly Media. (Free online edition by Green Tea Press.) https://allendowney.github.io/ThinkPython/