Checkpoint

Checkpoint: The Night Watch

Night falls on Gull Rock. The keeper pours fuel into the lantern tank and shouts out each amount. Some shouts are words, some are negative, and some would overflow the tank. Your program must keep the lantern safe all night.

This checkpoint uses everything from this chapter: raise, your own error type, several except blocks and else.

Assignment

The tank holds at most CAPACITY (10) units.

  1. Use the recipe to define TankFullError.
  2. Complete refill(level, text):
    • Convert text with int(). If it isn't a number, let the ValueError happen (don't catch it here).
    • If the amount is negative, raise ValueError.
    • If level + amount is more than CAPACITY, raise TankFullError.
    • Otherwise, return the new level.
  3. Complete night_watch(level, shouts). Call refill for each shout, in order, and keep the new level when it works. Build a list of notes, one per shout:
    • "ok" if the refill worked,
    • "full" if it raised TankFullError,
    • "bad" if it raised ValueError.
  4. night_watch returns a tuple: (final_level, notes).