Library Book Manager

class Book:
    def __init__(self, title, copies, loaned = 0, loaned_to = []):
        self.title = title
        self.copies = copies
        self.loaned = loaned
        self.loaned_to = loaned_to

    def display_info(self):
        print(f" Title: {self.title}", end = ", ")
        print(f"Total Copies: {self.copies}", end = ", ")
        print(f"Loaned Copies: {self.loaned}", end = ", ")
        if self.loaned_to == []:
            print("No Borrowers")
        else:
            print("Borrower(s): ", end = "")
            print(*self.loaned_to, sep = ", ")

    def loan_out(self, name):
        if self.get_available_copies() > 0:
            self.loaned += 1
            self.loaned_to.append(name)
            return True
        else:
            return False

    def return_book(self, name):
        if name in self.loaned_to:
            self.loaned -= 1
            self.loaned_to.remove(name)
            return True
        else:
            return False

    def get_available_copies(self):
        return self.copies - self.loaned


book1 = Book("1984", 5)
book2 = Book("To Kill a Mockingbird", 3)
book3 = Book("The Great Gatsby", 7)

book1.loan_out("Alice")
book1.loan_out("Bob")
book1.display_info()

book1.return_book("Alice")
book1.display_info()

print(f"Available copies: {book1.get_available_copies()}")

Output