
Boss
Boss: Expedition Toolkit

Boss Fight!
Every passing test breaks a shield.
The Guild's explorers keep a logbook of creature sightings. Each
line looks like date | island | creature. The Expedition Master
wants a command-line tool that turns the logbook into a report.
Time to use your whole toolbox!
Assignment
build_parser()returns anArgumentParser(prog="expedition")with three arguments:- a positional
logbook(the file path), --top: anint, default2,--since: defaultNone. Usetype=date.fromisoformat, so argparse turns the text into adate.
- a positional
read_logbook(path)reads the file withpathlib. It returns a list ofSighting(day, island, creature)namedtuples.dayis adate. Strip spaces from every part.- Skip blank lines.
- If any other line doesn't parse, call
log.warning("Skipping line %d: %r", number, line)and keep going. Line numbers start at 1.
main(argv)parsesargvand reads the logbook. If--sincewas given, it keeps only sightings on or after that day. Then it returns this report, with the lines joined by"\n":
Sightings: 6
Span: 2026-04-01 to 2026-04-04 (4 days)
Top: whale x3, gull x2
Busiest island: Amber Isle
- "Span" counts both the first and the last day.
- "Top" shows the
--topmost common creatures. Use aCounter. - If no sightings are left, return
"No sightings"instead.
build_parser()returns anArgumentParser(prog="expedition")with three arguments:- a positional
logbook(the file path), --top: anint, default2,--since: defaultNone. Usetype=date.fromisoformat, so argparse turns the text into adate.
- a positional
read_logbook(path)reads the file withpathlib. It returns a list ofSighting(day, island, creature)namedtuples.dayis adate. Strip spaces from every part.- Skip blank lines.
- If any other line doesn't parse, call
log.warning("Skipping line %d: %r", number, line)and keep going. Line numbers start at 1.
main(argv)parsesargvand reads the logbook. If--sincewas given, it keeps only sightings on or after that day. Then it returns this report, with the lines joined by"\n":
Sightings: 6
Span: 2026-04-01 to 2026-04-04 (4 days)
Top: whale x3, gull x2
Busiest island: Amber Isle
- "Span" counts both the first and the last day.
- "Top" shows the
--topmost common creatures. Use aCounter. - If no sightings are left, return
"No sightings"instead.
main.py Python sleeping
Press Run to try your code, then Check to test it.