Week 2 · Session 3

Operators, and Predicting the Future

Arithmetic, then a party trick built out of it.

The Arithmetic Operators

  • + - * — the ones you already know
  • / — division, and it always gives you a float: 10 / 5 is 2.0
  • // — integer division, throws away the remainder: 2026 // 100 is 20
  • % — modulo, keeps only the remainder: 11 % 7 is 4

Why % Matters More Than It Looks

  • Anything that wraps around is modulo: clocks, weekdays, months
  • A week has 7 days, so total % 7 always lands on one of them
  • 7 % 7 is 0. Wrapping all the way around returns you to the start
  • Today it gives you weekdays. In Lab 1 you will build it from scratch

Splitting a String Into Pieces

  • "11-25-2026".split("-") gives you ["11", "25", "2026"]
  • Unpack all three at once: mm, dd, yyyy = date.split("-")
  • Every piece is still a string. Convert before you calculate

Activity 2

The Doomsday Algorithm

Given any date, name its day of the week. Conway, 1973.

  • Each month has an anchor day, provided for you in DayFunctions.py
  • Split the year into century and decade, run the formula, take the remainder mod 7
  • Build it in named pieces, not one long line
  • Your job: work out how to split 2026 into 20 and 26

Test Against Your Code, Not For It

Two of the automated checks use a November date and a leap day, on purpose.

  • A wrong anchor day for one month passes every date you try in other months
  • A leap year bug hides for three years at a time
  • Three dates you picked yourself is not evidence. Pick the dates most likely to break it

Released Today

Lab 1: Computing a Calculator

Due Friday, September 11.

  • Five operations: + - * / %
  • Read an expression like 12 * 4, decide which operation was asked for, print the result
  • Build modulo without the % operator, out of your other functions
  • Worth 4.5 points. Your code review is graded separately

Before You Leave

  • Push your Doomsday work, even if it is unfinished
  • Run uv run gatorgrade --config gatorgrade.yml on both
  • Book a code review for Lab 1 early. Do not wait for Sep 11
← Exit
1 / 8