Week 2 — Basic Types, Operators & Modules

Interactive demos for Week 2 labs — numeric types, arithmetic expressions, division/modulo, strings, slicing, formatting, and more. Select a lab below.

Lab 2.20 — SSN Digit Extraction

How to use % (modulo) and // (integer division) to pull apart a 9-digit Social Security Number into its Area, Group, and Serial components.

1 / 4

Lab 2.24 — Midfix of 3

How to use len(), // (floor division), and string slicing to extract the middle 3 characters from a string.

word = +++toy+++
1 / 3

Lab 2.25 — Pizza Party Planner

How to use math.ceil(), math.pi, and arithmetic to calculate how many pizzas to order and the amount of sauce needed.

people = 7    hunger_level = 2
1 / 4
Variables

Lab 2.27 — Contact List Lookup

How to use find(), len(), and string slicing to search a contact list and extract the matching phone number.

contacts = Joe,123-5432 Linda,983-4123 Frank,867-5309
search = Frank
1 / 4