# Leo Salazar # 3/1/25 # Reading List # Required Book class as described in the assignment class Book: # constructor class def __init__(self, name, author, pages): self.name = name self.author = author self.pages = int(pages) # method to display book info def display_info(self): print(f'Title: {self.name}\nAuthor: {self.author}\nPages: {self.pages}') # method to determine whether book is long def is_long_read(self): if self.pages > 300: print("This is a long book!") else: print("This is a quick read.") # stores books library = [] # made a function since i did it more than once def print_list(library): print("Books:", end=' ') for i,book in enumerate(library): print(f'{i+1}.{book.name}', end=' ') print() # menu loop while True: # displays menu command = input("Welcome to your reading list.\n1. Add Book\n2. Select Book\n3. Remove Book\n4. Print List\n5. Quit\n") # i use match (like switch) but can easily be rewritten as if/else statements match command: # add book case '1': name = input("Enter the name of the book: ") author = input("Enter the author's name: ") pages = input("Enter the page count: ") library.append(Book(name, author, pages)) print("Book successfully added to list.") # select book case '2': if len(library) < 1: print("No books in list.") continue print_list(library) index = int(input('Which book would you like to select? ')) - 1 cur = library[index] print(f'{cur.name} selected.') # book options option = input("You can:\n1. Display info\n2. Is long read?\n") match option: case '1': cur.display_info() case '2': cur.is_long_read() case _: print('Invalid option. Returning to menu.') # remove book case '3': if len(library) < 1: print("No books in list.") continue print_list(library) index = int(input("Which book would you like to remove? ")) - 1 library.remove(library[index]) print("Successfully removed.") # print list case '4': if len(library) < 1: print("No books in list.") continue print_list(library) # quit case _: print("Goodbye.") break print()