Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(PYTHON)Write a set of functions that record and average user responses to the Oscar Nominated movies from 2018. Assume that each record includes 10 items.

(PYTHON)Write a set of functions that record and average user responses to the Oscar Nominated movies from 2018.

Assume that each record includes 10 items. The first item should be the user number (starting with 1), and the remaining 9 should be a opinion from 0 to 5 starts for each of 9 movies listed below. The fields should be as follows:

Opinions numbers have the following interpretation

Some example entries as a list of lists:

user number starting with 1

rating for The Shape of Water

rating for Darkest Hour

rating for Dunkirk

rating for Phantom Thread

rating for Three Billboards Outside Ebbing, Missouri

rating for Get Out

rating for The Post

rating for Call Me by Your Name

rating for Lady Bird

0 : I did not see the movie, 1: Terrible, 2: Bad, 3: Average, 4: Good, 5: Fantastic

user_ratings = [[1,0,0,4,0,5,0,0,2,0],[2,2,1,0,5,5,1,0,1,3],[3,5,0,2,2,4,3,3,0,1]]

For example, the first record is for user number 1. That person saw the movies: Dunkirk, Three Billboards Outside Ebbing, Missouri, and Call Me by Your Name, but did not see the other movies.

Write a function add_oscar_opinions that takes a filename ending in ".tsv" as an argument.

Use os.path.isfile to check if a file with that filename exists. If it does exist, then read in the contents of the file. Since the line is in .tsv format, you should split each line by tabs.

The first line should consist of labels (user_number, The Shape of Water, etc.)

Each subsequent line has 10 columns compatible with this problem -- the first position is the user number, the other positions are user ratings. Save this record as a list and keep a list of such records, e.g., like user_ratings above.

Also, for each movie, tally the number of users who saw the movie and the total of their ratings.

Embed a request for additional users in a while loop.

If there are no additional users, exit the while loop.

For each additional user, make an additional user number (1 greater than the highest user number previously found) and query the user regarding their views of each of the movies. Create a record of this information and store it. If the input file did not exist, then the first user to be entered by the system will be user number 1. For each movie that this user saw, add one to the number of users who saw the movie and add that user's rating to the total rating for that movie.

Next, for each movie, print the total number of users and the average rating for that movie (the total rating divided by the number of users who saw it).

Finally, write the records into a file as indicated by the input parameter. If this file previously existed, it will be overwritten. Otherwise, it will be newly created. It will include both info from users that were in the original file (if the file already existed) and info from users entered interactively.

Sample Files:

User The Shape of Water Darkest Hour Dunkirk Phantom Thread Three Billboards Outside Ebbing, Missouri Get Out The Post Call Me by Your Name Lady Bird 1 4 0 2 3 0 0 0 3 0 2 0 0 0 2 3 4 1 1 0 3 1 0 1 1 2 2 0 1 0 4 4 0 0 0 0 0 0 2 0 5 0 0 0 0 0 3 3 3 0 6 0 0 0 0 0 0 4 0 0 7 1 0 3 0 0 0 0 0 1
>>> average_movie_scores('sample_movie_ratings.tsv') Add one more user? Yes or No? yes Did you see the movie The Shape of Water? Enter a number from 0 to 5. O means you did not see the movie Otherwise the ratings are: 1: Terrible, 2: Bad, 3: Average, 4: Good, 5: Fantastic What is your rating? 5 Did you see the movie Darkest Hour? Enter a number from 0 to 5. O means you did not see the movie Otherwise the ratings are: 1: Terrible, 2: Bad, 3: Average, 4: Good, 5: Fantastic What is your rating? 0 Did you see the movie Dunkirk? Enter a number from 0 to 5. O means you did not see the movie Otherwise the ratings are: 1: Terrible, 2: Bad, 3: Average, 4: Good, 5: Fantastic What is your rating? 0 Did you see the movie Phantom Thread? Enter a number from 0 to 5. O means you did not see the movie Otherwise the ratings are: 1: Terrible, 2: Bad, 3: Average, 4: Good, 5: Fantastic What is your rating? 0 Did you see the movie Three Billboards Outside Ebbing, Missouri? Enter a number from 0 to 5. O means you did not see the movie Otherwise the ratings are: 1: Terrible, 2: Bad, 3: Average, 4: Good, 5: Fantastic What is your rating? 0 Did you see the movie Get Out? Enter a number from 0 to 5. O means you did not see the movie Otherwise the ratings are: 1: Terrible, 2: Bad, 3: Average, 4: Good, 5: Fantastic What is your rating? 1 Did you see the movie The Post? Enter a number from 0 to 5. O means you did not see the movie Otherwise the ratings are: 1: Terrible, 2: Bad, 3: Average, 4: Good, 5: Fantastic What is your rating? 1 Did you see the movie Call Me by Your Name? Enter a number from 0 to 5. O means you did not see the movie Otherwise the ratings are: 1: Terrible, 2: Bad, 3: Average, 4: Good, 5: Fantastic What is your rating? 1 Did you see the movie Lady Bird? Enter a number from 0 to 5. O means you did not see the movie Otherwise the ratings are: 1: Terrible, 2: Bad, 3: Average, 4: Good, 5: Fantastic What is your rating? 1 Add one more user? Yes or No? no The movie The Shape of Water had an average score of 3.0 . 5 people saw it in our sample. Nobody saw Darkest Hour The movie Dunkirk had an average score of 2.0 . 3 people saw it in our sample. The movie Phantom Thread had an average score of 2.0 . 3 people saw it in our sample. The movie Three Billboards Outside Ebbing, Missouri had an average score of 2.5 . 2 people saw it in our sample. The movie Get Out had an average score of 2.5 . 4 people saw it in our sample. The movie The Post had an average score of 2.25 . 4 people saw it in our sample. The movie Call Me by Your Name had an average score of 1.83 . 6 people saw it in our sample. The movie Lady Bird had an average score of 3.33 . 3 people saw it in our sample. >>> 

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions

Question

What is the perception that members have of the team?

Answered: 1 week ago