BASIC LIBRARY MANAGEMENT IN PYTHON

Library Management in Python

Program :

# Library Management
class Library:

def __init__(self, books):
self.books = books

# method for displaying books
def display_books(self):
print("Available Books...")
for i in range(len(self.books)):
print(f"{i+1}. {self.books[i]}")

# method for borrow books
def borrow_books(self, book_to_borrow):
print("You got the book")
(self.books).remove(book_to_borrow)

# method for return the books
def return_books(self, book_to_return):
(self.books).append(book_to_return)
print("You returned the book successfully")

# Object for the class 'Library'
books = ["Rich Dad Poor Dad", "The Secret", "Artificial Intelligence", "Elon Musk", "How to crack the coding interview"]
obj = Library(books)

msg = """
1. Display Books
2. Borrow Books
3. Return Books
"""

while True:
print(msg)
ch = int(input("Enter your choice : "))
print()

if ch == 1:
obj.display_books()
elif ch == 2:
book_name = input("Enter the book name to borrow : ")
obj.borrow_books(book_name.title())
elif ch == 3:
book_name = input("Enter the book name to return : ")
obj.return_books(book_name.title())
else:
print("Thank You \nCome Again")
exit()

Output :

Displaying Books

Borrowing Books

Returning Books

Exit from the Program


Comments

Popular posts from this blog

MOTION DETECTION AND TRACKING USING OPENCV AND PYTHON

BASIC HAND TRACKING USING PYTHON

COLOR DETECTION USING OPENCV AND PYTHON