Start of the python program you are to build a dictionary from the list that consists of the year as the key and the title and category as elements of a list that are the key’s corresponding value.

computer science

Description

Python program

Start of the python program you are to build a dictionary from the list that consists of the year as the key and the title and category as elements of a list that are the key’s corresponding value. Looking up the values for key ‘2000’, for example, returns [‘Gladiator’, ‘action’].

The program’s logic should be: 1. Read the movie list and build the dictionary 2. Process the user’s menu picks using the dictionary instead of the list

 

movies = [[1939, ‘Gone With the Wind’, ‘drama’], [1943, ‘Casablanca’, ‘drama’], [1965, 'The Sound of Music', 'musical'], [1969, ‘Midnight Cowboy’, ‘drama’], [1972, 'The Godfather', 'drama'], [1973, ‘The Sting’, ‘comedy’], [1977, 'Annie Hall', 'comedy'], [1982, ‘Gandhi’, ‘historical’], [1986, ‘Platoon’, ‘action’], [1990, 'Dances with Wolves', 'western'], [1992, 'Unforgiven', 'western'], [1994, 'Forrest Gump', 'comedy'], [1995, 'Braveheart', 'historical'], [1997, 'Titanic', 'historical'], [1998, 'Shakespeare in Love', 'comedy'], [2000, 'Gladiator', 'action'], [2001, ‘A Beautiful Mind, ‘historical’], [2002, 'Chicago', 'musical'], [2009, 'The Hurt Locker', 'action'], [2010, 'The Kings Speech', 'historical'], [2011, 'The Artist', 'comedy'], [2012, 'Argo', 'historical'], [2013, '12 Years a Slave', 'drama'], [2014, 'Birdman', 'comedy'], [2016, 'Moonlight', 'drama'], [2017, 'The Shape of Water', 'fantasy']]

 

The following is a sample menu to show how the options might be presented to the user:

 menu = """

1 - display winning movie by year

2 - display movie and category by year

 3 - add movie and category to list for an entered year

 p - print entire movie list pc – print movies in a selected category

q - quit

Select one of the menu options above

"""

For option 3, the program searches the list to see whether the movie is already there. If it isn’t, the user is prompted to enter a year, title, and category. There values are validated by your program as follows:

year – must be an integer between 1927 and 2019, inclusive

 title – must of a string of size less than 40

category – must be one of these values: (‘drama’, ‘western’, ‘historical’, ‘musical’, ‘comedy’, ‘action’, ‘fantasy’, ‘scifi’)

If the movie is already on the list, display the entry and prompt the user to ask if they want to replace it with new information. If yes, prompt for the new information and validate as above.

For options 1 and 2, if the requested year is not found in the list ask the user if they want to enter a year/title/category. If yes, prompt and validate as above.

 

 Hint: Since the code to prompt the user to movie information and validate it is repeated, consider writing a function that can be used by more than one menu option.


Related Questions in computer science category