
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
- In the
harbor.pytext, setTIDE = 2. - Also in
harbor.py, writedepth(base). It returnsbase + TIDE. - Also in
harbor.py, add a demo line:print("harbor demo:", depth(1)). Put it under anif __name__ == "__main__":guard, so importing stays quiet. - In the main program,
import harbor as hband printhb.depth(5). - Then
from harbor import TIDEand printTIDE.
- In the
harbor.pytext, setTIDE = 2. - Also in
harbor.py, writedepth(base). It returnsbase + TIDE. - Also in
harbor.py, add a demo line:print("harbor demo:", depth(1)). Put it under anif __name__ == "__main__":guard, so importing stays quiet. - In the main program,
import harbor as hband printhb.depth(5). - Then
from harbor import TIDEand printTIDE.
main.py Python sleeping
Press Run to try your code, then Check to test it.