class Book: def __init__(self, title, author, isbn): self.title = title self.author = author self.isbn = isbn # isbn means the International Standard Book Number self.borrowed = False self.published = False def mark_as_borrowed(self): self.borrowed = True def mark_as_returned(self): self.borrowed = False def __str__(self): return f"{self.title} by {self.author} (ISBN: {self.isbn})" class Library: def __init__(self): self.books = [] def add_book(self, book): self.books.append(book) def remove_book(self, isbn): self.books = [book for book in self.books if book.isbn != isbn] def search_by_title(self, title): return [book for book in self.books if title.lower() in book.title.lower()] def search_by_author(self, author): return [book for book in self.books if author.lower() in book.author.lower()] def display_books(self): for book in self.books: print(book) def mark_book_as_borrowed(self, isbn): for book in self.books: if book.isbn == isbn: book.mark_as_borrowed() break def main(): library = Library() while True: print("Welcome to my library!") print("1. Add Book") print("2. Remove Book") print("3. Search by Title") print("4. Search by Author") print("5. Display Books") print("6. Mark Book as Borrowed") print("7. quit") choice = input("Enter your choice: ") if choice == "1": title = input("enter the title of the book: ") author = input("enter the author of the book: ") isbn = input("enter the ISBN of the book: ") book = Book(title, author, isbn) print("Book added successfully") elif choice == "2": isbn = input("enter the ISBN of the book you want to remove: ") library.remove_book(isbn) print("Book removed successfully") elif choice == "3": title = input("enter the title of the book: ") result = library.search_by_title(title) if result: for book in result: print(book) else: print("Book not found") elif choice == "4": author = input("enter the author of the book: ") result = library.search_by_author(author) if result: for book in result: print(book) else: print("Author not found") elif choice == "5": library.display_books() elif choice == "6": isbn = input("enter the ISBN of the book to mark as borrowed: ") library.mark_book_as_borrowed(isbn) print("Book marked as borrowed successfully") elif choice == "7": print("Thank you for using my library!") break else: print("Invalid choice") if __name__ == "__main__": main()
Standard input is empty
class Book: def __init__(self, title, author, isbn): self.title = title self.author = author self.isbn = isbn # isbn means the International Standard Book Number self.borrowed = False self.published = False def mark_as_borrowed(self): self.borrowed = True def mark_as_returned(self): self.borrowed = False def __str__(self): return f"{self.title} by {self.author} (ISBN: {self.isbn})" class Library: def __init__(self): self.books = [] def add_book(self, book): self.books.append(book) def remove_book(self, isbn): self.books = [book for book in self.books if book.isbn != isbn] def search_by_title(self, title): return [book for book in self.books if title.lower() in book.title.lower()] def search_by_author(self, author): return [book for book in self.books if author.lower() in book.author.lower()] def display_books(self): for book in self.books: print(book) def mark_book_as_borrowed(self, isbn): for book in self.books: if book.isbn == isbn: book.mark_as_borrowed() break def main(): library = Library() while True: print("Welcome to my library!") print("1. Add Book") print("2. Remove Book") print("3. Search by Title") print("4. Search by Author") print("5. Display Books") print("6. Mark Book as Borrowed") print("7. quit") choice = input("Enter your choice: ") if choice == "1": title = input("enter the title of the book: ") author = input("enter the author of the book: ") isbn = input("enter the ISBN of the book: ") book = Book(title, author, isbn) print("Book added successfully") elif choice == "2": isbn = input("enter the ISBN of the book you want to remove: ") library.remove_book(isbn) print("Book removed successfully") elif choice == "3": title = input("enter the title of the book: ") result = library.search_by_title(title) if result: for book in result: print(book) else: print("Book not found") elif choice == "4": author = input("enter the author of the book: ") result = library.search_by_author(author) if result: for book in result: print(book) else: print("Author not found") elif choice == "5": library.display_books() elif choice == "6": isbn = input("enter the ISBN of the book to mark as borrowed: ") library.mark_book_as_borrowed(isbn) print("Book marked as borrowed successfully") elif choice == "7": print("Thank you for using my library!") break else: print("Invalid choice") if __name__ == "__main__": main()