Created
February 8, 2020 03:29
-
-
Save manojnaidu619/219bce072128206e4aeb006e0e0cb182 to your computer and use it in GitHub Desktop.
Library Management in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Library: | |
def __init__(self, listOfBooks): | |
self.books = listOfBooks | |
def showAllBooks(self): | |
print("\n") | |
for book in self.books: | |
print(book) | |
print("\n") | |
def lendBook(self, bookName): | |
if bookName in self.books: | |
self.books.remove(bookName) | |
print("You have successfully lent the book : ", bookName) | |
print("\n") | |
else: | |
print(f"Sorry, book named {bookName} Not Found!") | |
def addBook(self, bookName): | |
self.books.append(bookName) | |
print("Successfully returned the book : ", bookName) | |
print("\n") | |
class Customer: | |
def borrowBook(self): | |
borrowBook = str(input("Enter the Book name you would like to borrow : ")) | |
return borrowBook | |
def returnBook(self): | |
returnBook = str(input("Enter the Book name you would like to return : ")) | |
return returnBook | |
Books = ['Never again', 'Robinhood', 'Secret life'] | |
library = Library(Books) | |
customer = Customer() | |
while 1: | |
print("Enter 1 to Display all Books") | |
print("Enter 2 to Borrow a Book") | |
print("Enter 3 to return a Book") | |
print("Enter 4 to Quit") | |
choice = int(input()) | |
if choice is 1: | |
library.showAllBooks() | |
elif choice is 2: | |
book = customer.borrowBook() | |
library.lendBook(book) | |
elif choice is 3: | |
book = customer.returnBook() | |
library.addBook(book) | |
elif choice is 4: | |
quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment