Menu
CoddyTech

Tổng quan về dự án

Thuộc phần Lập trình hướng đối tượng trong hành trình Python của Coddy. Bài học 55 trên 64.

challenge icon

Thử thách

Trung bình

Trong thử thách này, bạn sẽ triển khai nền tảng cho hệ thống quản lý thư viện.

Chỉnh sửa library.py để triển khai các lớp cần thiết theo chú thích TODO. Tệp driver có nhiều tình huống kiểm thử để xác thực phần triển khai của bạn.

  • Làm theo các chú thích TODO trong library.py để được hướng dẫn từng bước
  • Triển khai lớp Library với phần khởi tạo và biểu diễn chuỗi phù hợp

Tự làm thử

from library import Library

# Xử lý đầy đủ các test case
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)

Tất cả bài học trong Lập trình hướng đối tượng

Tự luyện tập: Trình biên dịch Python online