Module: It is a python file having a set of function which we can import in our Application Program. We can consider a module as same as a code library.
Step to create Module in Python:
1. Create a Module program2. Now Create Main Program and if you want to access any function which is define in the Module program them you can Import Module in Your main Program.
Program:
1.Calculator.py
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):
l=a/b
m=a//b
if l>m:
return l
else:
return m
#Module End
2. Main Program:
from Calculator import*
a=int(input("Enter the 1st Number:"))
b=int(input("Enter the 2nd Number:"))
print("\nADDITION:",add(a,b))
print("Substraction:",sub(a,b))
print("Multiplication:",mul(a,b))
print("Division:",div(a,b))
Expected O/P: .....{ Running main Program}
Enter the 1st Number:12
Enter the 2nd Number:21
ADDITION: 33
Substraction: -9
Multiplication: 252
Division: 0.5714285714285714
0 Comments
Post a Comment