Week 1 · Programming Foundations
of 2
1. Programming as problem solving
Programming = giving a computer precise instructions to solve a problem. It does exactly what the instructions say, not what we meant. Human problem → logical steps → computer instructions.
Scripting = short programs that automate tasks. AI: prepare data, check values, simple statistics. Security: search logs, count failed events, prepare a report.
Input → processing → output: almost every program follows this pattern.
An algorithm is a clear sequence of steps, written before code: get the mark → compare with 50 → choose Pass or Fail.
Learning method: concept → command → example → practice.
2. Python building blocks
Python is the language/runtime that runs instructions; an editor, IDE or notebook is where we write them. Week 1 uses built-in Python only (no imports).
A statement is one instruction on a line; Python runs statements top to bottom.
Comments start with #; Python ignores them. Explain purpose, not every obvious line.
| Type | Holds | Example |
|---|---|---|
| str | text (in quotes) | "Ali", 'Dubai' |
| int | whole numbers | 25, 100 |
| float | decimals | 3.5, 99.95 |
| bool | True / False | True |
3. Variables and assignment
A variable is a name that stores a value for later use. = means "gets the value", not "is equal to".
Naming rules: letters, numbers, underscores; not starting with a number; no spaces or hyphens; case-sensitive (age ≠ Age). Prefer meaningful names: student_name, failed_logins, not x, thing.
Allowed: age2, total_price. Not allowed: 2age, student name, total-price.
4. Output with print()
print() shows one or more values; commas separate arguments and insert a space; each print() starts a new line. Commas can mix strings and numbers.
+ joins strings (concatenation): "Hello " + name. A string + a number fails unless the number becomes a string. * repeats a string: "-" * 20.
Valid variable name?