Skip to main content

Library Program in Python

 







class Library:
    def __init__(self,list,name):
        self.booklist= list
        self.name = name
        self.lendDict = {}
   
    def Disbook(self):
        print(f"We have Books in Library: {self.name}")
        for book in self.booklist:
            print(book,end=" , ")

    def addbook(self,book):
        self.booklist.append(book)
        print("Book is Added Successfully")

    def issuebook(self,user,book):
        if book not in self.lendDict.keys():
            self.lendDict.update({book:user})
            print("Book Database is updated. Now you can take book")
        else:
            print(f"Book has been taken by {self.lendDict[book]}")


    def returnbook(self,book):
        self.lendDict.pop(book)

if __name__ == '__main__':
    ak = Library(["C Programming","JAVA","Data Structure","Python"],"Main Library")


    while(True):
        print(f"\nWelcome to the {ak.name} Library")
        print("----- What you can to do -----")
        print("1. Display Book")
        print("2. Issue Book")
        print("3. Add Book")
        print("4. Return Book")
        choise = int(input())

        if choise == 1:
            ak.Disbook()
        elif choise ==2:
            book = input("Which book you want: ")
            user = input("Enter your name: ")
            ak.issuebook( user, book)
        elif choise ==3:
            book = input("Enter the name of the book you want to add: ")
            ak.addbook(book)
        elif choise ==4:
            book = input("Enter the name of the book you want to return: ")
            ak.returnbook(book)
        else:
            print("Enter the valid number! Try again")

        print("Press q for quit and c for continue")
        choise2 = ''
        while(choise2!="q" and choise2!="c"):
            choise2 = input()
            if choise2 =="q":
                exit()
            elif choise2 == "c":
                continue
           



Comments