Fill in

Your Own Module

Any .py file is a module. If ferry.py sits next to your program, import ferry loads it, with no .py in the import.

  • Python looks for modules in the folders listed in sys.path. The first one is your program's own folder.
  • A module's code runs once, on the first import. Python then caches it in sys.modules, so importing again is instant and doesn't rerun the file.

Making files in PyQuest

On your computer you'd create ferry.py in your editor. Here we write it with Path.write_text() onto the virtual disk. The small fresh() helper at the top clears Python's cache, so each run imports your latest version. You won't need it in real projects.

Assignment

Fill in the three ___ blanks:

  1. In the module text, set RATE to 3.
  2. Import the whole ferry module and print ferry.fuel_needed(10).
  3. Import just fuel_needed from ferry and print fuel_needed(5).