Quiz 2
Registry Synced

Programming in Python · Week 1 — Introduction to algorithms

1322 words
7 min read
2026-08-16

Reading compass

Now · Week map

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.

Week map

Algorithm idea → types → expressions → trace variable updates

Classify → Represent → Execute → Trap-check

  • Recognize: Ask: What is stored after x = 3 then x = 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.
  1. Typesint, float, str, bool — before any operator
  2. Precedence**, *, /, //, %, +, - — mixed arithmetic
  3. Division/ → float, // → floor — Python 3
  4. Assignmentname = expression — RHS fully evaluated first
  5. Comparison==, !=, <, chained: a<b<c — yields bool

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, False only.
  • str → string type → text sequence → "score", 'A'.
  • type(x) → returns type of value → type(3/2) is float in Python 3.

Literals and assignment

  • x = 5 → assignment statement → bind name x to value 5 → later x reads 5 until reassigned.
  • = is not equality test; equality is ==.
Mini-trace:
python
a = 10
b = a + 3
a = 2
print(b)
b becomes 13 before a changes; prints 13.

Expressions and operators

OperatorMeaningExample result
+add / concat3+4 → 7; "ab"+"c""abc"
-subtract7-2 → 5
*multiply / repeat3*4 → 12; "ha"*3"hahaha"
/true division (float)7/2 → 3.5
//floor division7//2 → 3
%remainder7%2 → 1
**power2**3 → 8
Precedence: parentheses, then **, then * / // %, then + -.
Mini-example: 2 + 3 * 42 + 1214. Not 20.

Algorithm tracing habit

Columns: line | variables after line | output.
python
x = 4
y = x * 2
x = y - 1
print(x + y)
linexynotes
14
248
378
4prints 15

Pattern families

Easy — Final value prediction

  • Straight-line assignments without branches.
  • Single print of 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.
  • print with comma-separated items vs concatenation.

Worked mini-examples

Example 1 — Division types.
python
a = 9 / 2      # 4.5 float
b = 9 // 2     # 4 int
c = 9 % 2      # 1
Example 2 — String vs int.
python
n = 7
msg = "Level " + str(n)   # "Level 7"
# "Level " + n  would error
Example 3 — Precedence.
python
result = 10 - 2 ** 3 + 1   # 10 - 8 + 1 = 3
Example 4 — Reassignment chain.
python
p = 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)

  1. What is printed?
python
x = 8
y = x // 3
x = y * 5
print(x)
  1. What is the type of 3 + 2.0? What is the type of 4 / 2?
  2. What is the value of 10 - 3 ** 2 + 1?
  3. After a = 6, b = a, a = 10, what are a and b?
  4. Write one expression that produces "Go" + "Go" using only the integer 2 and 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

TypeLiteral examples
int42, -7
float3.14, -0.5
boolTrue, 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

  1. What is stored after x = 3 then x = x + 2?
  2. What type is 3 / 2 in Python 3?
  3. Difference between expression and statement?

Practice loop

  1. Read Deep study (if present) or core concepts once.
  2. Recite the formula chain without looking.
  3. Open one easy pattern on the interactive atlas for week 1.
  4. Attempt without solutions; mark studied after an honest try.
  5. Say one trap aloud before closing the tab.
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.