University of Echahid Echeikh Larbi Tebessi
Faculty / Department of Architecture
Master 01 Architecture
Computer Programming
Introduction to Programming with Python
Master 01 Architecture
Speciality: Architecture
Lecture notes + examples
Yacine Belhocine
Laboratory of Mathematics Informatics and Systems (LAMIS)
Laboratory of Signals and Smart System (L3S)
Tebessa, Algeria
Academic Year 2025–2026
Computer Programming — Python Foundations M1 Architecture
Contents
1 Introduction: what does it mean to program? 3
1.1 Why programming is useful for architecture students . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Algorithmic thinking: from problem to solution 4
2.1 Algorithm vs. language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 A reusable method to design algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 The three universal building blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3 Data basics: variables, types, and expressions 5
3.1 A first example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 Operators you will use frequently . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Control flow: conditions and loops 6
4.1 Selection with if / elif / else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.2 Repetition with for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.3 The while loop (use carefully) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5 Core data structures: lists, tuples, and dictionaries 8
5.1 Rooms as tuples inside a list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
5.2 Counting categories with a dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
6 Algorithm patterns you should memorize 9
6.1 Pattern 1: sum and average . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
6.2 Pattern 2: minimum and maximum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
6.3 Pattern 3: filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
7 Applied examples (architecture-flavored) 11
7.1 Example A: room areas and compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1
Computer Programming — Python Foundations M1 Architecture
7.2 Example B: openings (doors/windows) and total width . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
8 Functions: making code reusable 13
8.1 A simple function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
8.2 Example: total area as a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
9 Organizing a Python script 14
9.1 The main entry point: if n ame= =” . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
m ain” :
10 The Python standard library: practical recipes 15
10.1 math: geometry-friendly calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
10.2 datetime: timestamps for logs and organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
10.3 pathlib: working with files and folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
11 Debugging: understanding and fixing errors 16
11.1 A loop inspection example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
12 Beginner good practices: readability first 17
12.1 Example: before / after . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
13 Mini-exercises to get started 18
13.1 Exercise set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
14 Quick reference and glossary 19
14.1 Quick reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
14.2 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
15 Conclusion and next steps 20
2
Computer Programming — Python Foundations M1 Architecture
1. Introduction: what does it mean to program?
Programming is the practice of expressing a solution as a sequence of precise steps that a computer can execute. A program is not magic: it is simply a structured set of instructions.
What matters most at the beginning is not knowing many commands, but learning how to convert a vague problem into a clear method.
A helpful analogy
An algorithm is like a recipe. The programming language is the language used to write the recipe. Python is designed to be readable: when the logic is clear, the code becomes
almost self-explanatory.
1.1 Why programming is useful for architecture students
Even without advanced tools, programming helps you build a disciplined approach to problem solving. Many architectural tasks involve repetition, checking constraints, or summarizing
lists of information. A script can automate repetitive work, reduce errors, and allow quick exploration of alternatives.
For example, when you have a list of rooms and their dimensions, you may need total areas, ratios, or warnings when a constraint is violated. Those tasks are fundamentally algorithmic:
once the logic is clear, writing code is simply a translation.
3
Computer Programming — Python Foundations M1 Architecture
2. Algorithmic thinking: from problem to solution
2.1 Algorithm vs. language
An algorithm is the method: the reasoning, the steps, the checks. A language is the notation used to express that method (Python, C, etc.). A strong beginner focuses first on the
algorithm: once the logic is correct, you can implement it in many languages.
2.2 A reusable method to design algorithms
A practical workflow is to start by clarifying the goal, then the data, then the steps. In other words, you decide what you want to produce, which inputs you have, which rules apply, and
finally you write the sequence of operations. This prevents the common beginner mistake of starting to code too early.
Good habit
Before writing code, write one or two sentences: “Input is ..., output is ..., the rule is ...”. This short preparation saves a lot of confusion later.
2.3 The three universal building blocks
Almost every program is built from the same three structures: sequence (do A then B), selection (if condition then ... else ...), and repetition (repeat steps using a loop). Complex programs
are simply combinations of these blocks.
4
Computer Programming — Python Foundations M1 Architecture
3. Data basics: variables, types, and expressions
A variable is a named container for a value. The goal is not to store data randomly, but to capture meaning. When you choose a clear variable name, you also clarify your reasoning.
In Python, basic types include integers (int), real numbers (float), text (str), and boolean values (bool). These types matter because operations depend on them.
3.1 A first example
L = 10.0
W = 6.0
area = L * W
print("Area =", area)
3.2 Operators you will use frequently
You will often use arithmetic (+ - * / **), comparisons (== != < <= > >=), and logic (and, or, not). These allow you to compute values and make decisions.
Readability first
A name like total_area tells the reader what is being computed. A name like x hides the intention and makes mistakes more likely.
5
Computer Programming — Python Foundations M1 Architecture
4. Control flow: conditions and loops
4.1 Selection with if / elif / else
A condition expresses a rule. In architecture-like examples, conditions are everywhere: if an area is below a threshold, raise an alert; if a ratio exceeds a limit, mark it as non-compliant.
area = 62
threshold = 60
if area >= threshold:
print("OK")
else:
print("Warning")
4.2 Repetition with for
A loop is how you handle lists. Instead of repeating code manually for each element, you write one block and apply it to each item.
values = [12, 15, 10, 18, 14]
total = 0
for v in values:
total += v
print("Total =", total)
4.3 The while loop (use carefully)
A while loop repeats while a condition is true. It is powerful, but beginners must ensure the condition eventually becomes false.
n = 5
while n > 0:
print(n)
6
Computer Programming — Python Foundations M1 Architecture
n -= 1
7
Computer Programming — Python Foundations M1 Architecture
5. Core data structures: lists, tuples, and dictionaries
A list stores multiple values in order. A tuple groups a small set of related values, for example (room name, length, width). A dictionary maps keys to values and is useful for counting
categories or storing properties by name.
5.1 Rooms as tuples inside a list
rooms = [("Bedroom", 3.5, 4.0), ("Kitchen", 3.0, 3.5)]
for name, L, W in rooms:
area = L * W
print(name, area)
5.2 Counting categories with a dictionary
elements = ["door", "wall", "window", "window", "door"]
count = {"door": 0, "window": 0, "wall": 0}
for e in elements:
count[e] += 1
print(count)
8
Computer Programming — Python Foundations M1 Architecture
6. Algorithm patterns you should memorize
Many beginner problems repeat the same patterns: compute a sum, compute a minimum/maximum, filter a list, or count items by category. Learning these patterns gives you a toolkit
you can reuse everywhere.
6.1 Pattern 1: sum and average
values = [12, 15, 10, 18, 14]
total = 0
for v in values:
total += v
avg = total / len(values)
print("Total =", total, "Avg =", avg)
6.2 Pattern 2: minimum and maximum
values = [12, 15, 10, 18, 14]
min_v = values[0]
max_v = values[0]
for v in values:
if v < min_v:
min_v = v
if v > max_v:
max_v = v
print("Min =", min_v, "Max =", max_v)
6.3 Pattern 3: filtering
9
Computer Programming — Python Foundations M1 Architecture
values = [12, 15, 10, 18, 14]
kept = []
for v in values:
if v >= 14:
[Link](v)
print(kept)
10
Computer Programming — Python Foundations M1 Architecture
7. Applied examples (architecture-flavored)
7.1 Example A: room areas and compliance
We compute the area of each room, accumulate a total, and then decide whether the total is compliant with a threshold. This example combines all three building blocks: a sequence of
operations, a loop, and a conditional decision.
Pseudo-code
1) set total = 0
2) for each room: compute area = L * W, add to total
3) if total ≥ threshold: print OK, else print Warning
rooms = [
("Bedroom", 3.5, 4.0),
("LivingRoom", 5.0, 6.2),
("Kitchen", 3.0, 3.5),
]
threshold = 60.0
total = 0.0
for name, L, W in rooms:
area = L * W
total += area
print(name, "=", area, "m2")
print("Total =", total, "m2")
if total >= threshold:
print("OK: area >= threshold")
else:
print("Warning: area < threshold")
11
Computer Programming — Python Foundations M1 Architecture
7.2 Example B: openings (doors/windows) and total width
elements = [
("wall", 4.2),
("door", 0.9),
("window", 1.2),
("window", 1.5),
]
count = {"door": 0, "window": 0}
sum_openings = 0.0
for typ, w in elements:
if typ in ("door", "window"):
count[typ] += 1
sum_openings += w
print("Doors:", count["door"])
print("Windows:", count["window"])
print("Total openings width:", sum_openings, "m")
12
Computer Programming — Python Foundations M1 Architecture
8. Functions: making code reusable
Functions help you avoid repetition and communicate meaning. When you put a calculation into a function, you separate the “what” from the “how”. This makes your script easier to
read and easier to test.
8.1 A simple function
def rectangle_area(L, W):
return L * W
print(rectangle_area(10, 6))
8.2 Example: total area as a function
def total_area(rooms):
total = 0.0
for name, L, W in rooms:
total += L * W
return total
rooms = [("Bedroom", 3.5, 4.0), ("Kitchen", 3.0, 3.5)]
print(total_area(rooms))
13
Computer Programming — Python Foundations M1 Architecture
9. Organizing a Python script
A typical Python file contains imports, function definitions, and a main entry point. This structure makes it clear where the program starts, and it prevents accidental execution when the
file is imported elsewhere.
9.1 The main entry point: if __name__ == "__main__":
def main():
print("Hello")
if __name__ == "__main__":
main()
14
Computer Programming — Python Foundations M1 Architecture
10. The Python standard library: practical recipes
Python includes many helpful modules. You do not need to memorize everything; instead, learn that these tools exist and know what problems they solve.
10.1 math: geometry-friendly calculations
import math
L = 10.0
W = 6.0
diag = [Link](L**2 + W**2)
print("Diagonal =", diag)
10.2 datetime: timestamps for logs and organization
from datetime import datetime
now = [Link]()
print("Now =", now)
print("Year =", [Link])
10.3 pathlib: working with files and folders
from pathlib import Path
p = Path("data")
print("Exists?", [Link]())
print("Absolute:", [Link]())
15
Computer Programming — Python Foundations M1 Architecture
11. Debugging: understanding and fixing errors
Beginners often think errors are a sign of failure. In reality, errors are a normal part of programming. The key skill is not avoiding errors, but learning how to read them and respond
calmly.
A simple strategy is to read the error message, check the line number, inspect the values using print, reduce the problem to a small example, fix one issue at a time, and re-run.
11.1 A loop inspection example
rooms = [("Bedroom", 3.5, 4.0), ("Kitchen", 3.0, 3.5)]
total = 0.0
for name, L, W in rooms:
area = L * W
print("DEBUG:", name, L, W, "area=", area)
total += area
print("Total =", total)
16
Computer Programming — Python Foundations M1 Architecture
12. Beginner good practices: readability first
Readability is not a luxury: it reduces mistakes. When code is readable, you can verify the logic more easily, explain it to others, and come back to it later without confusion.
12.1 Example: before / after
Before (hard to read)
Code:
a=0
for x in r:
a=a+x[1]*x[2]
print(a)
After (readable)
Code:
total_area = 0.0
for name, L, W in rooms:
room_area = L * W
total_area += room_area
print("Total area =", total_area)
17
Computer Programming — Python Foundations M1 Architecture
13. Mini-exercises to get started
These exercises are designed to train reading and reasoning, not memorization. Try to predict outputs before running code. Then run and compare. When you are wrong, explain why.
13.1 Exercise set
First, read the following and explain what it prints:
values = [2, 4, 6]
s = 0
for v in values:
s += v
print(s)
Then modify the list and predict again. After that, explain the difference between assignment (=) and comparison (==). Finally, write a function is_ok(area, threshold) returning True
or False.
18
Computer Programming — Python Foundations M1 Architecture
14. Quick reference and glossary
14.1 Quick reference
Assignment: x = 3. Condition: if condition: ... else: .... Loop: for x in list: .... Function: def f(x): return .... These four forms appear in almost every
beginner script.
14.2 Glossary
An algorithm is a step-by-step method to solve a problem. A variable is a named value. A type describes what kind of data a value is. A loop repeats a block. A condition selects a
branch. A function packages reusable logic. A script is a .py file executed by Python.
19
Computer Programming — Python Foundations M1 Architecture
15. Conclusion and next steps
The main lesson is that programming is reasoning made explicit. If your logic is correct and your steps are clear, coding becomes a translation. You will repeatedly use the same building
blocks: sequence, selection, repetition. You will also reuse the same algorithmic patterns: sum/average, min/max, filtering, and counting.
A natural continuation is to practice input/output, data cleaning, simple sorting and searching, and to build a small mini-project: read a list of rooms, compute a report, and export it as
text or CSV.
Final message
Understand before you code. Clear logic produces clear programs.
20