Bird
0
0
LLDsystem_design~10 mins

Class design (Book, Member, Librarian, Loan) in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a class for Book with a constructor.

LLD
class Book:
    def __init__(self, title, author):
        self.title = title
        self.author = [1]
Drag options to blanks, or click blank then click option'
Aauthor
Btitle
Cself
Dbook
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning title to self.author by mistake.
2fill in blank
medium

Complete the code to add a method that returns the member's name.

LLD
class Member:
    def __init__(self, name):
        self.name = name
    
    def get_name(self):
        return [1]
Drag options to blanks, or click blank then click option'
Aname
Bself.name
Cself
Dmember_name
Attempts:
3 left
💡 Hint
Common Mistakes
Returning just name without self. causes an error.
3fill in blank
hard

Fix the error in the Loan class constructor to correctly assign the book and member.

LLD
class Loan:
    def __init__(self, book, member):
        self.book = book
        self.member = [1]
Drag options to blanks, or click blank then click option'
Amember
Bself.member
Cself.book
Dbook
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning self.member to itself causes no change.
4fill in blank
hard

Fill both blanks to complete the method that checks if a book is available (not loaned).

LLD
class Librarian:
    def __init__(self):
        self.loans = []
    
    def is_book_available(self, book):
        for loan in self.loans:
            if loan.[1] == book:
                return [2]
        return True
Drag options to blanks, or click blank then click option'
Abook
BFalse
CTrue
Dmember
Attempts:
3 left
💡 Hint
Common Mistakes
Returning True inside the loop causes wrong availability.
5fill in blank
hard

Fill all three blanks to create a method that adds a new loan if the book is available.

LLD
class Librarian:
    def __init__(self):
        self.loans = []
    
    def add_loan(self, book, member):
        if self.is_book_available(book):
            new_loan = Loan([1], [2])
            self.loans.[3](new_loan)
            return True
        return False
Drag options to blanks, or click blank then click option'
Abook
Bmember
Cappend
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove instead of append causes errors.