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
Input: G,F,P,C,G,F,P,C,G,P,C
1 / 6
Variables

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.

scores = [85, 92, 78, 95]
1 / 6
Variables

Lab 3.14 — List Basics: Slicing

How list indexing and slicing work in Python — positive indices, negative indices, the [start:end] syntax, and .count().

Input: 1 2 3 4 4
1 / 5
Variables

Lab 3.15 — Mascot Mania

How to use namedtuple to create structured data with named fields, and _replace() to update immutable records.

1 / 5
Variables