This task involves creating two scripts, one for each part! TASK 1 1. Create a Python module named module.py. 2. This module must define four functions: a. add(a, b) b. subtract(a, b) c. multiply(a, b) d. divide(a, b) e. Divide must check for division by zero and return an error message if it encounters it. 3. Each function should take two arguments and perform the corresponding mathematical operation. Return the result, don’t print it in the function. 4. Include a main() function that tests these functions with some example inputs. Ensure that you print the results of the function calls here in the main function and provide the appropriate labels. 5. The main() function must only run automatically if the module is being run directly, not when imported. TASK 2 6. Create another Python script named in the same directory as module.py. 7. This new script must import the module you created in Part 1 of this task. a. Tip: You import the module with import
This task involves creating two scripts, one for each part!
TASK 1
1. Create a Python module named module.py.
2. This module must define four functions:
a. add(a, b)
b. subtract(a, b)
c. multiply(a, b)
d. divide(a, b)
e. Divide must check for division by zero and return an error message if it encounters it.
3. Each function should take two arguments and perform the corresponding mathematical operation. Return the result, don’t print it in the function.
4. Include a main() function that tests these functions with some example inputs. Ensure that you print the results of the function calls here in the main function and provide the appropriate labels.
5. The main() function must only run automatically if the module is being run directly, not when imported.
TASK 2
6. Create another Python script named in the same directory as module.py.
7. This new script must import the module you created in Part 1 of this task.
a. Tip: You import the module with import <name of file to import wthout the .py extension)
8. In this script, call each function from the module with different inputs than the ones you used when testing it in the main() method of the module. You don’t need a main function in this script file.
9. Ensure that the main() function from the imported module does not run when you execute this script. a. You shouldn’t need to do anything here if you completed step 5, just verify that this is working correctly.
Here is a screenshot of the expected behavior, testing all scenarios described above. Replicate
this functionality in your solutions, including the formatting and outputs of all messages.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images