
PYTHON — Python Greeter Module Exercise
Data is the new oil. It’s valuable, but if unrefined it cannot really be used. — Clive Humby
In this exercise, you will create a Python module called greeter.py that includes a single function, greet(). The function should take a string parameter named name and print the message "Hello, " followed by the provided name. Here's a step-by-step guide to completing the exercise:
First, create a new file named greeter.py and define the greet() function in it. Below is the code to accomplish this:
# greeter.py
def greet(name):
print(f"Hello, {name}!")Save the file and you now have a greeter.py module with the greet() function implemented.
To test the greet() function, you can create another Python script in the same directory and import the greeter module. Then, call the greet() function with a name as an argument. Here's an example:
# main.py
import greeter
greeter.greet("Bartosz")
greeter.greet("Tappan")When you run main.py, it should print the following output:
Hello, Bartosz!
Hello, Tappan!By following these steps, you have successfully built a greeter module in Python. This exercise demonstrates the creation of a simple module and function, allowing you to understand the basics of modular programming in Python.
