0% found this document useful (0 votes)
2 views

90_python

The document outlines the implementation of Python packages for various utilities, including a math utility package for arithmetic, geometry, and statistics functions, a unit converter for length, temperature, and weight conversions, and a library management system for managing books and members. Each section includes code examples for creating and using these packages. The document concludes by stating that the Python programs were successfully completed.

Uploaded by

71762305061
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

90_python

The document outlines the implementation of Python packages for various utilities, including a math utility package for arithmetic, geometry, and statistics functions, a unit converter for length, temperature, and weight conversions, and a library management system for managing books and members. Each section includes code examples for creating and using these packages. The document concludes by stating that the Python programs were successfully completed.

Uploaded by

71762305061
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

EX NO :10

20.03.2025 MODULES AND PACKAGES

AIM :

To implement the modules and packages in python .

QUESTION 1:

1. Create a Python package called mathutils that contains following modules: [25]
 arithmetic.py: Implements basic arithmetic operations (add, subtract, multiply,
divide), power and square root functions.
 geometry.py: Implements functions to calculate the area and circumference of a
circle, area and perimeter of a square, a triangle and a rectangle.
 statistics.py: Implements functions to calculate the mean, median, and standard
deviation.
Use this package in a Python script to perform some calculations.

CODE 1:

from mathutils import Arithmetic as a,geometry as g,statistics as s


aa=int(input("Enter a :"))
b=int(input("Enter b :"))
print("ADDITION :",a.add(aa,b))
print("SUBTRACTION :",a.sub(aa,b))
print("DIVISION :",a.divide(aa,b))
print("MULTIPLICATION :",a.multiply(aa,b))
print("POWER :",a.power(aa,b))
print("SQUARE :",a.square(aa,b))

s=int(input("Enter the side of the square :"))


c=int(input("Enter the radius of the circle "))
l=int(input("Enter the length of the rectangle : "))
br=int(input("Enter the breadth of the rectangle : "))
a=int(input("Enter the side of the triangle : "))
b=int(input("Enter the base of the triangle: "))
h=int(input("Enter the height of the triangle :"))
print("SQUARE AREA : ",g.sarea(s))
print("SQUARE PERIMETER : ",g.speri(s))
print("CIRCLE AREA : ",g.carea(c))
print("CIRCLE PERIMETER : ",g.cperi(c))
print("TRIANGLE AREA :",g.tarea(b,h))
print("TRIANGLE PERIMETER :",g.tperi(a,b,h))
print("RECTANGLE AREA :",g.rarea(l,br))
print("RECTANGLE PERIMETER :",g.rperi(l,br))

l=[]
n=int(input("Enter the no of elements in the list :"))
for i in range(1,n+1):
ne=int(input())
l.append(ne)
print("MEAN :" ,s.mean(l))
print("MEDIAN :",s.median(l))
print("STANDARD DEVIATION :",s.stdev(l))

OUTPUT 1 :

def add(a,b):
return a+b
def sub(a,b):
return a-b
def multiply(a,b):
return a*b
def divide(a,b):
return a/b
def power(a,b):
return a**b
def square(a,b):
return a**(1/2)

def speri(a):
return 4*a
def carea(c):
return c*3.14*c
def cperi(c):
return c*2*3.14
def tarea(a,b):
return (a*b)/2
def tperi(a,b,c):
return a+b+c
def rarea(a,b):
return a*b
def rperi(a,b):
return 2*(a+b)
def mean(l):
return sum(l)/len(l)
def median(l):
return l[len(l)/2]

QUESTION 2 :

2.Create a Python package called unitconverter that helps convert:


o Length: Convert between meters, kilometers, miles, and feet.
o Temperature: Convert between Celsius and Fahrenheit.
o Weight: Convert between kilograms, grams and pounds.
Use this package in a Python script to perform conversions.
CODE 2:

from unitconverter import temperature as t,weight as w,length as l


kg=int(input("Enter the kg :"))
print("GRAM :",w.kg_g(kg))
print("POUND :",w.kg_p(kg))

g=int(input("Enter the gram :"))


print("Pound :",w.g_p(g))
print("KG :",w.g_kg(g))
p=int(input("Enter the pound :"))
print("GRAM :",w.p_g(p))
print("KG :",w.p_kg(p))
c=int(input("Enter 1 for c and 0 for f"))
if(c==1):
ce=int(input("Enter the celcius :"))
print("FAHRENHEIT :",t.c_f(ce))
if(c==0):
f=int(input("Enter the fahrenheit :"))
print("CELCIUS :",t.f_c(f))
km=int(input("Enter the km : "))
print("METER :",l.km_m(km))
print("FEET :",l.km_f(km))
print("MILE :",l.km_mi(km))

m=int(input("Enter the meter : "))


print("KM :",l.m_km(m))
print("FEET :",l.m_f(m))
print("MILE :",l.m_mi(m))
f=int(input("enter the feet : "))
print("KM : ",l.f_km(f))
print("FEET :",l.f_m(f))
print("MILE :",l.f_mi(f))
mi=int(input("Enter the mile :"))
print("MILE :",l.m_km(mi))
print("METER :",l.km_m(mi))
print("FEET:",l.m_f(mi))

OUTPUT:
def m_km(m):
return m/1000
def km_m(km):
return km*1000
def mi_f(mi):
return m+32
def f_mi(f):
return f-32
def km_f(km):
return km*1000*3.28
def km_mi(km):
return km*0.62
def m_f(m):
return m*3.28
def m_mi(m):
return (m*0.62)/1000
def f_km(f):
return 3.28*f
def f_m(f):
return f*1000*3.28
def f_c(f):
return (f-32)*5/9
def c_f(c):
return c*(9/5)+32
def kg_g(kg):
return kg*1000
def kg_p(kg):
return kg*2.2
def g_kg(g):
return g/1000
def g_p(g):
return (g/1000)*2.2
def p_kg(p):
return p/2.2
def p_g(p):
return p*1000*2.2

QUESTION 3 :

3. Create a Python package called librarymanagement that performs following services:


 Book: Add and remove books, search by title/author.
 Lend: Track borrowed books, due dates, and late fees.
 Member: Manage members and their borrowing history.
Write a Python script that allows a user to borrow and return books. [40]
CODE 3:

from book import Book, BookManager

from lend import LendManager

from member import Member

def main():

book_manager = BookManager()
lend_manager = LendManager()

book1 = Book("1984", "George Orwell")

book2 = Book("To Kill a Mockingbird", "Harper Lee")

book_manager.add_book(book1)

book_manager.add_book(book2) member1 = Member("Alice")

member2 = Member("Bob")

while True:

print("\nLibrary Management System")

print("1. Borrow Book")

print("2. Return Book")

print("3. Search Book by Title")

print("4. Search Book by Author")

print("5. Exit")

choice = input("Choose an option: ")

if choice == '1':

title = input("Enter book title to borrow: ")

books = book_manager.search_by_title(title)

if books:

book = books[0]

due_date = lend_manager.lend_book(book, member1)

if due_date:

member1.add_to_history(book)

print(f"{book} borrowed. Due date: {due_date.strftime('%Y-%m-%d')}")


else:

print(f"{book} is not available.")

else:

print("Book not found.")

elif choice == '2':

title = input("Enter book title to return: ")

books = book_manager.search_by_title(title)

if books:

book = books[0]

member = lend_manager.return_book(book)

if member:

late_fee = lend_manager.check_late_fees(book)

if late_fee > 0:

print(f"{book} returned. Late fee: ${late_fee:.2f}")

else:

print(f"{book} returned on time.")

else:

print(f"{book} was not borrowed.")

else:

print("Book not found.")

elif choice == '3':

title = input("Enter book title to search: ")

books = book_manager.search_by_title
OUTPUT :

RESULT :

Thus the python programs to implement the modules and packages were completed successfully.

You might also like