Complete the code to declare a class for Book with a constructor.
class Book: def __init__(self, title, author): self.title = title self.author = [1]
title to self.author by mistake.The constructor assigns the parameter author to the instance variable self.author.
Complete the code to add a method that returns the member's name.
class Member: def __init__(self, name): self.name = name def get_name(self): return [1]
name without self. causes an error.The method should return the instance variable self.name to access the member's name.
Fix the error in the Loan class constructor to correctly assign the book and member.
class Loan: def __init__(self, book, member): self.book = book self.member = [1]
self.member to itself causes no change.The constructor should assign the parameter member to self.member.
Fill both blanks to complete the method that checks if a book is available (not loaned).
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
True inside the loop causes wrong availability.The method checks if any loan's book matches the given book. If yes, it returns False meaning not available.
Fill all three blanks to create a method that adds a new loan if the book is available.
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
remove instead of append causes errors.The method creates a new Loan with book and member, then appends it to self.loans.
