This module focuses on understanding and utilizing Python modules and packages, as well as practicing namespaces in functions.
- Solution
- Description:
Task "How to Divide?":
- Create two modules,
fake_math
andtrue_math
, each containing adivide
function that handles division in different ways.fake_math.divide
: Returns an error message when dividing by zero.true_math.divide
: Returns infinity when dividing by zero (usingmath.inf
).
- Import these functions into a main module using the
as
keyword to avoid name conflicts, and test them by passing values, including zero as the divisor.
- Create two modules,
- Solution
- Description:
Task "Function Scope":
- Create a function
test_function
and define an inner functioninner_function
within it that prints a message. Callinner_function
withintest_function
and test whetherinner_function
can be called outside oftest_function
.
- Create a function