0% found this document useful (0 votes)
23 views11 pages

Python Libraries for Class 12 CS

The document provides an overview of Python libraries and modules, specifically focusing on user-defined modules and their creation. It includes examples of functions for calculating volumes of different geometric shapes and demonstrates how to import and use these functions in a menu-driven program. Additionally, it briefly mentions the random module and its functions.

Uploaded by

akulbisht
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views11 pages

Python Libraries for Class 12 CS

The document provides an overview of Python libraries and modules, specifically focusing on user-defined modules and their creation. It includes examples of functions for calculating volumes of different geometric shapes and demonstrates how to import and use these functions in a menu-driven program. Additionally, it briefly mentions the random module and its functions.

Uploaded by

akulbisht
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like