from c1470_util import * # open files to get the quotations. def main(): filename = 'quotes.txt' f = open(filename, 'r', encoding='utf-8') lines = f.readlines() f.close() # dict to store quotations. Keys are authors quotations = {} for i in range(0, len(lines), 2): author = lines[i].strip() # remove trailing white spaces if i + 1 < len(lines): quotation = lines[i+1].strip() if author not in quotations: # new author quotations[author] = [] # create a list for the new author quotations[author].append(quotation) if not quotations: print("No quotations loaded. Exiting.") exit while True: print("=" * 20) author_name = input("Enter an author's name (or 'quit' to exit): ").strip() if author_name.lower() == 'quit': break authors = keys_with_substring(quotations, author_name) if authors: for author in authors: print(f"\nQuotations by {author}:") for i, quote in enumerate(quotations[author]): print(f" [{i+1}] {quote}") else: print(f"No quotations found for '{author_name}'.") if __name__ == "__main__": main()