
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:
- In the module text, set
RATEto3. - Import the whole
ferrymodule and printferry.fuel_needed(10). - Import just
fuel_neededfromferryand printfuel_needed(5).
Fill in the three ___ blanks:
- In the module text, set
RATEto3. - Import the whole
ferrymodule and printferry.fuel_needed(10). - Import just
fuel_neededfromferryand printfuel_needed(5).
main.py Python sleeping
Press Run to try your code, then Check to test it.