Computer Science with Python Class 12
Python Libraries
Module and Library in Python
Computer Science Dept. Mount Carmel School AN
Computer Science with Python Class 12
Computer Science Dept. Mount Carmel School AN
Computer Science with Python Class 12
Computer Science Dept. Mount Carmel School AN
Computer Science with Python Class 12
Example 1
Example 2
Computer Science Dept. Mount Carmel School AN
Computer Science with Python Class 12
Example 3
User defined Module:
A user defined module is also created like a program and is saved with the extension .py
which is a collection of multiple function definitions. It is imported in other Python
programs using import statement to access the defined functions.
Computer Science Dept. Mount Carmel School AN
Computer Science with Python Class 12
# Example
#save this file or module with [Link]
def volcube(r):
v=r*r*r
return(v)
def volcuboid(l,b,h):
v=l*b*h
return(v)
def volcylinder(r,h):
v=3.14*r*r*h
return(v)
def volcone(r,h):
v=(3.14*r*r*h)/3
return(v)
#A menu driven Program
import ModuleVol
print("[Link] of a cube")
print("[Link] of a cuboid")
print("[Link] of a cylinder")
print("[Link] of a cone")
ch=int(input("\nEnter your choice:"))
if ch==1:
x=float(input("Enter side of cube(in cm.)"))
print([Link](x))
elif ch==2:
x=float(input("Enter length of cuboid(in cm.)"))
y=float(input("Enter breadth of cuboid(in cm.)"))
Computer Science Dept. Mount Carmel School AN
Computer Science with Python Class 12
z=float(input("Enter height of cuboid(in cm.)"))
print([Link](x,y,z))
elif ch==3:
x=float(input("Enter radius of cylinder(in cm.)"))
y=float(input("Enter height of cylinder(in cm.)"))
print([Link](x,y))
elif ch==4:
x=float(input("Enter radius of cone(in cm.)"))
y=float(input("Enter height of cone(in cm.)"))
print([Link](x,y))
else:
print("wrong choice“)
Random Module
Computer Science Dept. Mount Carmel School AN
Computer Science with Python Class 12
1. random ( ) Function :
Computer Science Dept. Mount Carmel School AN
Computer Science with Python Class 12
2. randint ( ) Function :
3. randrange( ) Function:
Example 1
Computer Science Dept. Mount Carmel School AN
Computer Science with Python Class 12
Example 2
Problem 1
Computer Science Dept. Mount Carmel School AN
Computer Science with Python Class 12
Problem 2
Problem 3
Computer Science Dept. Mount Carmel School AN