Week 3 — Loops, Lists & String Operations
Interactive demos for Week 3 labs — for loops, if/elif branching, list building with append(), and counting patterns. Select a lab below.
Lab 3.16 — Peter’s Ant Sorter
Peter found different types of ants but is allergic to Fire ants! This demo shows how to count each type with a for loop + if/elif chain, and build a filtered list without Fire ants using append().
G — Garden
F — Fire
P — Picnic
C — Carpenter
Concept — How For Loops Work
A for loop repeats code for each item in a sequence. This demo traces a loop that calculates the sum and average of a list of test scores, one iteration at a time.
Lab 3.14 — List Basics: Slicing
How list indexing and slicing work in Python — positive indices, negative indices, the [start:end] syntax, and .count().
Lab 3.15 — Mascot Mania
How to use namedtuple to create structured data with named fields, and _replace() to update immutable records.