Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python Please In this assignment we are going to practice reading data from a file and writing the results of your program into a

In Python Please

In this assignment we are going to practice reading data from a file and writing the results of your program into a file.

You are being provided with a sample data file: movies.txt that contains a list of movies. Each line of the file contains the movie title, the movie genre, the release year, the running time in minutes, and the star rating. A typical line in the file has the following format:

movie-title genre release-year running-time rating ---the fields are separated by tabs.

For example:

The Godfather Drama 1972 275 4.7 Love Actually Romance 2003 136 3.8 Encanto Musical 2021 109 3.8 Tangled Musical 2010 100 4.5 

Write a program that:

Asks the user to enter the name of the data file.

this must be handled by the getFileName() function which validates the name of the file, e.g. it makes sure the file exists.

Ask the user to enter the title of a movie.

Find out if that movie is in the data file.

this must be handled by the movieFinder() function -- see details below.

If the movie is found in the file, display its running time and movie star rating. If not, display an appropriate message.

Next, ask the user for a genre and save in an output file all movies of that genre.

this must be handled by the createReport() function.

Your solution must include the following three functions:

getFileName():

the function has no parameters.

the function asks the user to enter the name of the data file. If the file does not exist then it asks the user to try again until a valid file name is provided.

the function returns a string that represents the name of a valid file.

movieFinder(inFile, movieTitle):

the function has two parameters:

a file object for a file that has been opened for reading.

a string that represents the title of the movie to look for.

the function returns a tuple in the form (boolean, int, float) that indicates whether the movie was found in the file, its running time and its rating. If a movie is not found, return 0 for the integer and float values in the result tuple.

createReport(inFile, genre):

the function has two parameters:

a file object for a file that has been opened for reading.

a string that represents a genre.

the function returns an integer that represents the number of movies of the given genre, found in the data file

the function performs the following tasks:

Opens an output file named movieReport.txt

Parses the data file looking for movies of the given genre.

Each time a movie of given genre is found, the movie title is written in the output file and the movie count is increased.

At the bottom of the file write movie genre and the total number of movies matching that genre.

Below are a sample/typical runs:

Enter name of the data file: movies.txt Enter title of a movie: Encanto Encanto has a running time of 109 minutes and a rating of 3.8 stars. What type of movie would you like to watch? musical Genre: Musical Movies Found: 2 

Here is an example of what the output file may look like:

Encanto Tangled Genre: Musical Total movies: 2 

Here is another sample run:

Enter name of the data file: data.txt Error: that file does not exist. Try again. Enter name of the data file: moviesData.txt Error: that file does not exist. Try again. Enter name of the data file: movies.txt Enter title of a movie: giant Giant was not found in the file. What type of movie would you like to watch? Crime Genre: crime Movies Found: 0 

Here is an example of what the output file may look like:

Genre: Crime Total movies: 0 

Notes:

The purpose of this problem is to practice using file input/output.

Please make sure to submit a well-written program. Good identifier names, useful comments, and spacing will be some of the criteria that will be used when grading this assignment.

This assignment can be and must be solved using only the materials that have been discussed in class. Do not look for alternative methods that have not been covered as part of this course.

Use of global variables is not allowed.

Your program must have an appropriate header comment

Functions must be documented using docstrings

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions