books_in_library = ["In Search of Lost Time by Marcel Proust", "Ulysses by James Joyce",
"One Hundred Years of Solitude by Gabriel Garcia Marquez",
"War and Peace by Leo Tolstoy", "The Odyssey by Homer"]
logbooks = {}
class Library:
def __init__(self, library_name, library_books_list):
self.libraryname = library_name
self.bookslist = library_books_list
def books_available(self):
if books_in_library != []:
print(f"The book(s) available for lending in {self.libraryname} are:")
for index, book in enumerate(books_in_library):
print(index+1,"-", book)
if books_in_library == []:
print(f"All the books in {self.libraryname} has benn lended. Plz wait till users return the books.")
def lend_books(self):
lender_name = input("Plz enter your kind name: ")
print(f"Hi, {lender_name}. Welcome to {self.libraryname}.")
library1.books_available()
print("---------------------------------------------------------------------")
lended_book = input("Plz input the name of the book that you want to lend: ")
print("\n")
if lended_book in books_in_library:
print(f"""Congrats! {lended_book} has been issued to you, {lender_name} form {self.libraryname}.
Plz keep it in good shape and return it on time.""")
elif lended_book in logbooks.keys():
print(f"""Sorry! {lended_book} book has already been issued by {logbooks[lended_book]}.
You can wait till {logbooks[lended_book]} returns the book
or you can issue some other book that is available in the {self.libraryname}.""")
else:
print("""Either the book is not available in our library,
or you have entered the book name case-insenitively.""")
if lended_book in books_in_library:
books_in_library.remove(lended_book)
logbooks.update({lended_book: lender_name})
print("\n")
print("Issued Books along with the issuer Names:\n", logbooks)
print("\n")
library1.books_available()
def donate_books(self):
donated_book = input("Plz input the name of the book that you want to donate: ")
print(f"You have successfully donated the book '{donated_book}' to {self.libraryname}. Thanks.")
books_in_library.append(donated_book)
def return_books(self):
returned_book = input("Plz input the name of the book that you want to return: ")
print(f"You have successfully returned {returned_book} to {self.libraryname}. Thanks.")
books_in_library.append(returned_book)
library1.books_available()
library1 = Library("Abdur_Library", books_in_library)
while True:
print("\n")
print(">> Welcome to Library Management System <<")
print("Note: Plz choose your option from the following.")
print(""" 1 - What books are available in the library?
2 - I want to lend a book.
3 - I want to retun a book back.
4 - I want to donate a book to the library.
5 - Exit the library.""")
option = input("Which option will you choose? ")
if option == "1":
print("So you want to know what books are available in this library.")
library1.books_available()
elif option == "2":
if books_in_library == []:
print(f"Sorry! All the books in our library has benn lended. Plz wait till users return the books.")
if books_in_library != []:
print("So you want to lend a book from this library.")
print("---------------------------------------------------------------------")
library1.lend_books()
elif option == "3":
print("So you want to return a book back to the library.")
library1.return_books()
elif option == "4":
print("So you want to donate a book to our library. That's great!")
library1.donate_books()
elif option == "5":
option = input("""Do you really want to exit?
y - Yes
n - No
""")
if option == "y":
exit()
else:
library1.books_available()
else:
print("Not a valid option!")
Comments
Post a Comment
Write something to CodeWithAbdur!