Programming in Python · Week 1 — Introduction to algorithms
1322 words
7 min read
2026-08-16T00:00:00.000Z
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
types, expressions, tracing state — concepts, pattern families, and traps for Quiz 2 week 1. # Week 1 — introduction to algorithms > **Quiz 2 scope:** Weeks 1–8 per IITM May 2026 foundation courses.

Week 1 — introduction to algorithms
Quiz 2 scope: Weeks 1–8 per IITM May 2026 foundation courses. Source baseline: IITM BS admissions important-dates calendar · May 2026 cycle. Times on assessments are operational conventions — verify hall ticket.
Part of the Quiz 2 prep system%20%C2%B7%20%5BWeeks%201%E2%80%938%20index%5D(.%2Fmay-2026-python-quiz-2-weeks-1-8-prep) · Pattern atlas · Formula chains.
Week map
Algorithm idea → types → expressions → trace variable updates
Classify → Represent → Execute → Trap-check
- Recognize: Ask: What is stored after
x = 3thenx = x + 2? - Procedure: Execute assignments top to bottom without skipping. When a variable is reassigned, old value is lost. For expressions, apply operator precedence before assignment.
- Variations / traps: Watch for: Using
=for comparison instead of==.
Formula chain (compressed)
Trace types → evaluate expressions with precedence → assignment updates bindings.
- Types —
int, float, str, bool— before any operator - Precedence —
**, *, /, //, %, +, -— mixed arithmetic - Division —
/ → float, // → floor— Python 3 - Assignment —
name = expression— RHS fully evaluated first - Comparison —
==, !=, <, chained: a<b<c— yields bool
Open interactive formula desk · Week 1 tab.
Deep study
Programming in Python · Week 1 — Algorithms and types
First-week Python is about predictable state change: what each line does to memory, and which types allow which operations.
Week map
Algorithm as ordered steps → variables and assignment → built-in types → expressions vs statements → operator precedence → tracing print output.
Type notation
int→ integer type → whole numbers →17,-4,0.float→ floating type → decimal approximations →3.0,-0.25,2.718.bool→ boolean type → truth values →True,Falseonly.str→ string type → text sequence →"score",'A'.type(x)→ returns type of value →type(3/2)isfloatin Python 3.
Literals and assignment
x = 5→ assignment statement → bind namexto value 5 → laterxreads 5 until reassigned.=is not equality test; equality is==.
Mini-trace:
pythona = 10 b = a + 3 a = 2 print(b)
b becomes 13 before a changes; prints 13.Expressions and operators
| Operator | Meaning | Example result |
|---|---|---|
+ | add / concat | 3+4 → 7; "ab"+"c" → "abc" |
- | subtract | 7-2 → 5 |
* | multiply / repeat | 3*4 → 12; "ha"*3 → "hahaha" |
/ | true division (float) | 7/2 → 3.5 |
// | floor division | 7//2 → 3 |
% | remainder | 7%2 → 1 |
** | power | 2**3 → 8 |
Precedence: parentheses, then
**, then * / // %, then + -.Mini-example:
2 + 3 * 4 → 2 + 12 → 14. Not 20.Algorithm tracing habit
Columns: line | variables after line | output.
pythonx = 4 y = x * 2 x = y - 1 print(x + y)
| line | x | y | notes |
|---|---|---|---|
| 1 | 4 | — | |
| 2 | 4 | 8 | |
| 3 | 7 | 8 | |
| 4 | prints 15 |
Pattern families
Easy — Final value prediction
- Straight-line assignments without branches.
- Single
printof expression or variable. - Identify type of literal or simple expression.
Medium — Mixed-type expressions
- Division always float in Python 3.
- Floor division and mod with negatives (know course convention; often positive mod for quiz).
- String
+vs numeric+— types must match for numeric add.
Hard — Multi-variable dependency chains
- Reassignment overwrites; old value gone unless another name still references it (week 1 usually one name per value).
- Expression on RHS fully evaluated before LHS update.
printwith comma-separated items vs concatenation.
Worked mini-examples
Example 1 — Division types.
pythona = 9 / 2 # 4.5 float b = 9 // 2 # 4 int c = 9 % 2 # 1
Example 2 — String vs int.
pythonn = 7 msg = "Level " + str(n) # "Level 7" # "Level " + n would error
Example 3 — Precedence.
pythonresult = 10 - 2 ** 3 + 1 # 10 - 8 + 1 = 3
Example 4 — Reassignment chain.
pythonp = 1 q = p + 4 # q = 5 p = q # p = 5 q = p + 2 # q = 7 # p is 5, q is 7
Traps
- Using
=in a condition (week 2 topic, but appears early in distractors). - Assuming
/gives integer quotient in Python 3. - Concatenating str with int without
str(). - Reading code bottom-up when state evolves top-down.
- Confusing
//with/.
Diagnostic (try yourself)
- What is printed?
pythonx = 8 y = x // 3 x = y * 5 print(x)
-
What is the type of
3 + 2.0? What is the type of4 / 2? -
What is the value of
10 - 3 ** 2 + 1? -
After
a = 6,b = a,a = 10, what areaandb? -
Write one expression that produces
"Go" + "Go"using only the integer2and string operations (no quotes in the expression except on"Go").
ChatGPT prep archive
Archived import for extra depth — complements the notes above, not official IITM material.
Core concepts
- Algorithm: ordered steps that transform input to output; state is values in memory at each step.
- Types: int, float, bool, str; type tells which operations are legal.
- Expressions evaluate to a value; statements change state (assignment).
- Tracing: follow line order; update variables; print shows current value.
Notation & vocabulary
| Type | Literal examples |
|---|---|
| int | 42, -7 |
| float | 3.14, -0.5 |
| bool | True, False |
| str | "hello" |
Pattern families
Easy — Predict final value
Execute assignments top to bottom without skipping. When a variable is reassigned, old value is lost. For expressions, apply operator precedence before assignment.
Medium — Type of expression
Identify operand types first. Mixed int/float often yields float in Python 3. Division
/ is float; // is floor division. Comparison expressions yield bool.Hard — Trace with dependencies
When later lines use earlier variables, build a small table: line number, variable, new value. Watch order: RHS fully evaluated before LHS update.
Drill these on the pattern atlas — filter to week 1.
Traps
- Using
=for comparison instead of==. - Assuming
/returns int in Python 3. - Reading code bottom-up when state evolves top-down.
- Ignoring that strings concatenate with
+, not add numerically.
Retrieval prompts
- What is stored after
x = 3thenx = x + 2? - What type is
3 / 2in Python 3? - Difference between expression and statement?
Practice loop
- Read Deep study (if present) or core concepts once.
- Recite the formula chain without looking.
- Open one easy pattern on the interactive atlas for week 1.
- Attempt without solutions; mark studied after an honest try.
- Say one trap aloud before closing the tab.