Create a user defined module with simple functions for: addition, subtraction, multiplication, division, modulo, square, factorial. Write a program to import the module and access functions defined in the module in python

Code

create mymath.py and app.py

mymath.py
# create add, sub, mul, div, mod, square, factorial

def add(a, b):
return a + b

def sub(a, b):
return a - b

def mul(a, b):
return a * b

def div(a, b):
return a / b

def mod(a, b):
return a % b

def square(a):
return a * a

def factorial(a):
if a == 0:
return 1
else:
return a * factorial(a - 1)



app.py

import mymath

print(mymath.add(1, 2))
print(mymath.sub(1, 2))
print(mymath.mul(1, 2))
print(mymath.div(1, 2))
print(mymath.mod(1, 2))
print(mymath.square(2))
print(mymath.factorial(5))

Output