Complete-Python-Mastery
Complete-Python-Mastery copied to clipboard
Assignment : Implementing a Library Management System
Objective:
The purpose of this assignment is to practice the concepts of Object-Oriented Programming (OOP) in Python by implementing a simple Library Management System.
Instructions:
-
Class Definitions:
-
Create a class
Bookwith the following attributes:title: A string representing the title of the book.author: A string representing the author of the book.isbn: A string representing the ISBN number of the book.available: A boolean indicating whether the book is available for borrowing (default isTrue).
-
Create a class
Memberwith the following attributes:name: A string representing the name of the member.member_id: An integer representing the unique ID of the member.borrowed_books: A list to keep track of books borrowed by the member (initially empty).
-
Create a class
Librarywith the following attributes and methods:-
books: A list to store all the books available in the library. -
members: A list to store all the members of the library. -
Methods:
add_book(book): Adds aBookobject to the library.remove_book(isbn): Removes a book from the library based on its ISBN.register_member(member): Registers a newMemberto the library.borrow_book(member_id, isbn): Allows a member to borrow a book if it is available.return_book(member_id, isbn): Allows a member to return a borrowed book.list_available_books(): Lists all available books in the library.list_borrowed_books(member_id): Lists all books borrowed by a specific member.
-
-
-
Implementation:
- Implement the classes and methods as described.
- Handle edge cases such as attempting to borrow a book that is not available, returning a book that was not borrowed, etc.
-
Testing:
- Create instances of
BookandMember. - Test the functionality of the
Libraryclass by adding books, registering members, borrowing and returning books. - Ensure that the list of available books updates correctly after borrowing and returning.
- Create instances of
Example:
# Create books
book1 = Book("The Alchemist", "Paulo Coelho", "978-0061122415")
book2 = Book("To Kill a Mockingbird", "Harper Lee", "978-0060935467")
# Create members
member1 = Member("Rajesh Kumar", 1)
member2 = Member("Sita Sharma", 2)
# Create a library
library = Library()
# Add books to the library
library.add_book(book1)
library.add_book(book2)
# Register members
library.register_member(member1)
library.register_member(member2)
# Borrow a book
library.borrow_book(1, "978-0061122415")
# List available books
library.list_available_books()
# Return a book
library.return_book(1, "978-0061122415")
# List borrowed books for a member
library.list_borrowed_books(1)
Submission:
- Submit the Python code file (.py) containing the implementation of the classes and a main function that tests the functionality.
- Include comments explaining your code and the logic behind your implementation.
Bonus:
- Extend the
Libraryclass to handle late returns by implementing a methodcalculate_fine(member_id, days_late)that calculates a fine based on the number of days a book is returned late.
This assignment will help reinforce the principles of OOP in Python, including class design, inheritance, and method implementation.
Hello sir, I have implemented this library application portal in a slightly different way as you specified in the question / issue. However, along with the functions you specified in the question, I have included other functions also in the program to perform other tasks that are commonly performed in a library management application. Here is the link where you can find the code on my git profile.
https://github.com/AnmolDixitB13/Python/blob/main/library%20management%20portal