Course Content

Mini Project 1 (OOPs Library) Solution | Python Tutorials For Absolute Beginners In Hindi #101

This is the solution to first ever Mini Project of this series. In the end of the series we will look towards solving full fledge projects. The problem statement was:


The task is to create an “Online Library Management System”. For this, you have to create a library class which includes the following methods:

  • Displaybook() : To display the available books
  • Lendbook(): To lend a book to a user
  • Addbook(): To add a book in the library
  • Returnbook(): To return the book in the library.

As you have created a library class, now you will create an object and pass the following parameters in the constructor.

HarryLibrary=Library(listofbooks, library_name)

After that, create a main function and run an infinite while loop which asks the users for their input whether they want to display, lend, add or return a book.


Maintain a dictionary for the users who own a book. Dictionary should take book name as a key and name of the person as a value. Whenever you lend a book to a user, you should maintain a dictionary.

Code as described/written in the video

# Create a library class
# display book
# lend book - (who owns the book if not present)
# add book
# return book

# HarryLibrary = Library(listofbooks, library_name)

#dictionary (books-nameofperson)

# create a main function and run an infinite while loop asking
# users for their input

class Library:
    def __init__(self, list, name):
        self.booksList = list = name
        self.lendDict = {}

    def displayBooks(self):
        print(f"We have following books in our library: {}")
        for book in self.booksList:

    def lendBook(self, user, book):
        if book not in self.lendDict.keys():
            print("Lender-Book database has been updated. You can take the book now")
            print(f"Book is already being used by {self.lendDict[book]}")

    def addBook(self, book):
        print("Book has been added to the book list")

    def returnBook(self, book):

if __name__ == '__main__':
    harry = Library(['Python', 'Rich Daddy Poor Daddy', 'Harry Potter', 'C++ Basics', 'Algorithms by CLRS'], "CodeWithHarry")

        print(f"Welcome to the {} library. Enter your choice to continue")
        print("1. Display Books")
        print("2. Lend a Book")
        print("3. Add a Book")
        print("4. Return a Book")
        user_choice = input()
        if user_choice not in ['1','2','3','4']:
            print("Please enter a valid option")

            user_choice = int(user_choice)

        if user_choice == 1:

        elif user_choice == 2:
            book = input("Enter the name of the book you want to lend:")
            user = input("Enter your name")
            harry.lendBook(user, book)

        elif user_choice == 3:
            book = input("Enter the name of the book you want to add:")

        elif user_choice == 4:
            book = input("Enter the name of the book you want to return:")

            print("Not a valid option")

        print("Press q to quit and c to continue")
        user_choice2 = ""
        while(user_choice2!="c" and user_choice2!="q"):
            user_choice2 = input()
            if user_choice2 == "q":

            elif user_choice2 == "c":

Be the first person to comment!



No downloadable resources for this video. If you think you need anything, please post it in the QnA!

Course Announcements

Any Course related announcements will be posted here