Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

import sysdef processFile ( file _ path ) : try: with open ( file _ path, ' r ' ) as file: titles = [

import sysdef processFile(file_path): try: with open(file_path, 'r') as file: titles =[] release_dates =[] for line in file: if line.startswith("Release date"): # Extract release date from the line release_date = line.split(":")[1].strip() release_dates.append(release_date) else: # Extract movie title from the line title = line.strip() titles.append(title) return titles, release_dates except FileNotFoundError: print(f"Error: File not found at {file_path}") sys.exit()def search(user_input, titles, release_dates): try: index = titles.index(user_input) return release_dates[index] except ValueError: return Nonedef output(release_date): if release_date: print(f"Release date: {release_date}") else: print("Movie not found.")def main(): file_path = "horror_movies.txt" print("RKO HORROR MOVIE SEARCH") user_input = input("What RKO horror movie do you want to look up?
").strip() titles, release_dates = processFile(file_path) release_date = search(user_input, titles, release_dates) output(release_date)if __name__=="__main__": main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions