Command Palette

Search for a command to run...

Hectal
Phase 6: Modules, Packages and Projects
Python · Exercise 3 of 5 PreviousNext
Intermediate

Write a module and import it

Use Path("greeter.py").write_text(...) to create a file greeter.py. The file must define a function greet(name) that returns "Hello, ", then the name, then "!". For example, greet("Asha") returns Hello, Asha!.

Call importlib.invalidate_caches(), then import greeter and print greeter.greet("Asha").

What Check tests

  1. The module greeter was imported
  2. greeter.greet("Asha") returns Hello, Asha!
  3. greeter.greet("Ravi") returns Hello, Ravi!
  4. An empty name still works
  5. The module has the name greeter
  6. The program prints Hello, Asha!

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.