class Library: def __init__(self, filename='books.txt'): self.file = filename self.books = [] self.load_books() def __del__(self): self.save_books() def load_books(self): try: with open(self.file, 'r') as file: self.books = file.readlines() except FileNotFoundError: open(self.file, 'w').close() def save_books(self): with open(self.file, 'w') as file: file.writelines(self.books) def list_books(self): for book in self.books: book_info = book.split(', ') print(f"{book_info[0]}, {book_info[1]}") def add_book(self, title, author, publication_date, page_number): book = f"{title}, {author}, {publication_date}, {page_number}\n" self.books.append(book) print("Book added successfully.") def remove_book(self, title): self.books = [book for book in self.books if not book.startswith(title)] print("Book removed successfully.") def main(): lib = Library() while True: print("\n*** MENU ***\n1) List Books\n2) Add Book\n3) Remove Book\n4) Press q for Quit program") choice = input("Enter your choice: ") if choice == '1': lib.list_books() elif choice == '2': title = input("Enter the title of the book: ") author = input("Enter the author of the book: ") publication_date = input("Enter the publication date of the book: ") page_number = input("Enter the page number of the book: ") lib.add_book(title, author, publication_date, page_number) elif choice == '3': title = input("Enter the title of the book you want to remove: ") lib.remove_book(title) elif choice == 'q' or choice == 'Q': print("Quitting program...") break else: print("Invalid choice, please choose again.") if __name__ == "__main__": main()