Menu
CoddyTech

Project Overview

Part of the Object Oriented Programming section of Coddy's Python journey. Lesson 55 of 64.

challenge icon

Challenge

Medium

In this challenge, you'll implement the foundation for a Library Management System.

Edit library.py to implement the required classes following the TODO comments. The driver file contains extensive test scenarios that validate your implementation.

  • Follow the TODO comments in library.py for step-by-step guidance
  • Implement the Library class with proper initialization and string representation

Try it yourself

from library import Library

# Comprehensive test case handler
test_case = input()

if test_case == "basic_library_creation":
    library_name = "Test Library"
    library = Library(library_name)
    print(library)
    
elif test_case == "library_attributes":
    library = Library("Test Library")
    print(f"Name: {library.name}")
    print(f"Books: {len(library.books)}")
    print(f"Users: {len(library.users)}")

elif test_case == "multiple_libraries":
    library1 = Library("Library 1")
    library2 = Library("Library 2")
    print(library1)
    print(library2)

elif test_case == "empty_name":
    library = Library("")
    print(library)

elif test_case == "special_characters":
    library = Library("!@#$%^&*()")
    print(library)

elif test_case == "very_long_name":
    long_name = "A" * 100
    library = Library(long_name)
    print(library)

elif test_case == "add_books_users":
    library = Library("Test Library")
    library.books.extend(["Book1", "Book2", "Book3"])
    library.users.extend(["User1", "User2"])
    print(library)

elif test_case == "empty_lists":
    library = Library("Test Library")
    print(f"Books length: {len(library.books)}")
    print(f"Users length: {len(library.users)}")

elif test_case == "type_validation":
    library = Library(123)
    print(library)

All lessons in Object Oriented Programming

Practice on your own: Online Python compiler