0

I'm trying to figure out a way to define my function for loaning a book within a class. This is what I have so far:

class Library:
    # the class constructor
    def __init__(self, books, patrons):
        self.books=books
        self.patrons=patrons
    def __str__(self):
        s="Patron("
        for patron in self.patrons:
            s+=str(patron) + ', '
        if len(self.patron) != 0:
            s= s[:-2]
        s+=']'
        for book in self.books:
            s+=str(book) + ', '
        if len(self.books) != 0:
            s= s[:-2]
        s+='])'
        return s

and I have my function:

    def loan_book(self, patron_id, book_id):
        existence= False
        for i in self.patrons:
            if i.patron_id==patron_id:
                return True
        raise LookupError
        for i in self.books:
            if i.book_id==book_id:
                return True 
        raise LookupError
        for i in patron:
            if i.book_id==book_id:
                raise DuplicateIdError()
            self.books.remove(book_id)
            patron.books.append(book_id)

I just want to make sure it is correct. any help?

2
Contributors
1
Reply
27
Views
3 Years
Discussion Span
Last Post by woooee
0

What is "patrons"? It looks like a list of Patron class instances. If so, please include the Patron class code also. In loan_book() you only check the book_id if the patron is not found. If the patron is found you return before the book lookup.

Edited by woooee

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.