Checkpoint

Checkpoint: The Harbor Module

The harbor master keeps rewriting the same tide math in every program. Time to put it in one module that every ship can import!

This checkpoint uses the whole chapter: writing a module, the __main__ guard, and two import styles.

The setup at the top is the same fresh() helper as before.

Assignment

  1. In the harbor.py text, set TIDE = 2.
  2. Also in harbor.py, write depth(base). It returns base + TIDE.
  3. Also in harbor.py, add a demo line: print("harbor demo:", depth(1)). Put it under an if __name__ == "__main__": guard, so importing stays quiet.
  4. In the main program, import harbor as hb and print hb.depth(5).
  5. Then from harbor import TIDE and print TIDE.