701 words
4 min read
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
# Computational Thinking · Week 1 — Variables and state CT week 1 builds **representations**: naming quantities, picking datatypes, and tracing state through flowcharts or pseudocode. ## Week map Problem → variables as named state → datatypes → iterators → flowchart symbols → state snapshots → input/output boxes.

Computational Thinking · Week 1 — Variables and state
CT week 1 builds representations: naming quantities, picking datatypes, and tracing state through flowcharts or pseudocode.
Week map
Problem → variables as named state → datatypes → iterators → flowchart symbols → state snapshots → input/output boxes.
Representation notation
- Variable → name bound to a value that may change →
count,total,name. - State → all current variable values at one instant → snapshot table one row per step.
- Iterator → variable stepping through a sequence or count →
ifrom 0 to n-1. - Datatype → kind of value → determines legal operations → number vs string vs list.
Flowchart symbols
| Shape | Role | Example action |
|---|---|---|
| Oval | start / end | Start, Stop |
| Rectangle | process | total ← total + price |
| Diamond | decision | score ≥ 50? |
| Parallelogram | input / output | Read age, Print sum |
Arrow direction defines order. At a diamond, follow one branch label (Y/N or T/F).
Choosing a representation
Ask three questions:
- Single vs collection? One score → number; list of scores → list.
- Fraction allowed? Integer count vs float average.
- Text vs number? ID as string even if digits; phone codes not for arithmetic.
Mini-example: Track 5 quiz scores → list
scores length 5, not five unrelated names unless table fixed.State snapshot tracing
Problem: start
x=3, y=1. Process: y ← x + y, then x ← y - 2.| step | x | y |
|---|---|---|
| init | 3 | 1 |
| after 1st | 3 | 4 |
| after 2nd | 2 | 4 |
Read as: assignment uses current values when evaluating right-hand side.
Pattern families
Easy — Read flowchart step
- Follow arrows; update rectangles; branch at diamond once.
- Identify start/end and missing arrow bugs in diagrams.
- Match parallelogram to Read/Print in trace.
Medium — Choose datatype and names
- From word problem, list variables and types.
- Distinguish index (position) vs value at index.
- Flowchart with two variables swapping — track both columns.
Hard — Full state table
- Multi-step with decision: duplicate row only along taken branch.
- Iterator introduced mid-flow: when does
iincrement? - Detect unreachable rectangle (no arrow in).
Worked mini-examples
Example 1 — Simple trace.
Start
a=10, b=2. a ← a - b → a=8. b ← a + b → b=10.Example 2 — Decision.
n=7. Diamond: n > 5? Yes → msg ← "big". Else branch skipped. msg is "big".Example 3 — Iterator intro.
i=0, sum=0. Loop body: sum ← sum + i, i ← i + 1, repeat while i < 4.| i | sum after step |
|---|---|
| 0 | 0 |
| 1 | 0 |
| 2 | 1 |
| 3 | 3 |
| 4 | 6 |
Loop stops when
i becomes 4.Example 4 — Wrong type choice.
Storing
price = "12.50" then total = price + 5 concatenates strings in Python-like semantics — representation error if numeric total intended.Traps
- Skipping decision branch label — both paths mentally.
- Same name for two concepts (
totalfor both count and sum). - Using value before rectangle that assigns it.
- Iterator confused with stored data value (
ivsitem[i]). - Flowchart arrow bypassing update rectangle.
Diagnostic (try yourself)
-
Start
p=5,q=3. Executep ← p + qthenq ← p - q. What are finalpandq? -
A flowchart diamond asks
x < 0. Ifx = 0, which branch (Y/N) is taken for “less than zero”? -
You need to store a student’s 8 weekly quiz percentages. One variable or a collection? Which datatype class?
-
Trace
c=1,d=4, thenc ← d,d ← c. What arecandd? (Watch order.) -
In a state table, why duplicate rows only on the taken branch after a decision?