Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
import sysdef processFile ( file _ path ) : try: with open ( file _ path, ' r ' ) as file: titles = [
import sysdef processFilefilepath: try: with openfilepath, r as file: titles releasedates for line in file: if line.startswithRelease date": # Extract release date from the line releasedate line.split:strip releasedates.appendreleasedate else: # Extract movie title from the line title line.strip titles.appendtitle return titles, releasedates except FileNotFoundError: printfError: File not found at filepath sysexitdef searchuserinput, titles, releasedates: try: index titles.indexuserinput return releasedatesindex except ValueError: return Nonedef outputreleasedate: if releasedate: printfRelease date: releasedate else: printMovie not found."def main: filepath "horrormovies.txt printRKO HORROR MOVIE SEARCH" userinput inputWhat RKO horror movie do you want to look up strip titles, releasedates processFilefilepath releasedate searchuserinput, titles, releasedates outputreleasedateif namemain: main
import sysdef processFilefilepath: try: with openfilepath, r as file: titles releasedates for line in file: if line.startswithRelease date": # Extract release date from the line releasedate line.split:strip releasedates.appendreleasedate else: # Extract movie title from the line title line.strip titles.appendtitle return titles, releasedates except FileNotFoundError: printfError: File not found at filepath sysexitdef searchuserinput, titles, releasedates: try: index titles.indexuserinput return releasedatesindex except ValueError: return Nonedef outputreleasedate: if releasedate: printfRelease date: releasedate else: printMovie not found."def main: filepath "horrormovies.txt printRKO HORROR MOVIE SEARCH" userinput inputWhat RKO horror movie do you want to look up
strip titles, releasedates processFilefilepath releasedate searchuserinput, titles, releasedates outputreleasedateif namemain: main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started