Question

For Python 3.8! Copy and paste the following bolded code into IDLE: movies = [[1939, 'Gone...

For Python 3.8!

Copy and paste the following bolded code into IDLE:

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, 'Ghandi', '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', 'hisotrical'],
          [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'],
          [2015, 'Spotlight', 'drama'],
          [2016, 'Moonlight', 'drama'],
          [2017, 'The Shape of Water', 'fantasy']]

menu = """
Movie List 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 all movies in the list
pc - print by category
q - quit

Enter a selection from the above menu and hit 'Enter'
"""

selection = ''
while selection != 'q':
    print(menu)
    selection = input("Please select one of the options found above: ")

    if selection == "1":
      
    elif selection == "2":

    elif selection == "3":

    elif selection == 'p':

    elif selection == 'pc':
        category = input("Please enter the desired category: ")
          
    elif selection == 'q':
        break

This will be your starting template. From here, do the following:

1) Change the provided "movies" list (found above) to a dictionary with the year as the key and the movie title & category as the corresponding values. The rest of the code should reference the dictionary, NOT the list.

2) When run, the program displays a simple menu of options for the user. Depending on the option selected, a movie title for a given year is displayed, the title and category are displayed, or only movies in a specified category are displayed.

The program reads the options and validates that the choice is on the menu. If not, the user is prompted to enter a valid one. When a year is entered for options 1 and 2 a check is made to ensure it’s within a valid range (1927to 2019) and whether that year’s movie information is already in the dictionary. If the year is out of range the user is prompted to re-enter. If it is in range and in the dictionary, the information is displayed.

For the ‘p’ option the program iterates through the dictionary and prints the movie information in a readable format. Printing the entire dictionary with one print command is not sufficient. For ‘pc’, prompt for a category and print every movie title in the dictionary with the specific category. Print ‘no matches’ if there are no movies in the entered category.

3) For option 3, the program searches the dictionary 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here are the complete implementation of all the choices.

Refer the screenshot for code indentation.

=======================================================================

=======================================================================

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, 'Ghandi', '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', 'hisotrical'],
          [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'],
          [2015, 'Spotlight', 'drama'],
          [2016, 'Moonlight', 'drama'],
          [2017, 'The Shape of Water', 'fantasy']]
menu = """
Movie List 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 all movies in the list
pc - print by category
q - quit
Enter a selection from the above menu and hit 'Enter'
"""


movie_dict = {}
for row in movies:
    movie_dict[row[0]] = row[1:]

selection = ''
while selection != 'q':
    print(menu)
    selection = input("Please select one of the options found above: ")
    if selection == "1":
        year = int(input('Enter year (1927-2019): '))
        if 1927 <= year and year <= 2019:
            print('Winning Movie for year {} was {}'.format(year, movie_dict.get(year)))
        else:
            print('Year not in range.')
    elif selection == "2":
        year = int(input('Enter year (1927-2019): '))
        if 1927 <= year and year <= 2019:
            value = movie_dict.get(year)
            print('Winning Movie for year {} was {} and belong to {} category'.format(year, value[0], value[1]))
        else:
            print('Year not in range.')
    elif selection == "3":
        movie_name = input('Enter movie name: ')
        if movie_name in [movie[0] for movie in movie_dict.values()]:
            print('Movie by that name already exist')
            replace = input('Enter \'yes\' if you want to replace \'no\' to exit:')
            if replace == 'yes':
                year = int(input('Enter year: '))
                title = input('Enter movie title: ')
                category = input('Enter category: ')
                if 1927 <= year and year <= 2019 and len(title) <= 40 and \
                                category in ['drama', 'western', 'historical', 'musical', 'comedy', 'action', 'fantasy',
                                             'scifi']:
                    movie_dict[year] = [title, category]
                else:
                    print('Validation failed.')

        else:
            year = int(input('Enter year: '))
            title = input('Enter movie title: ')
            category = input('Enter category: ')
            if 1927 <= year and year <= 2019 and len(title) <= 40 and \
                            category in ['drama', 'western', 'historical', 'musical', 'comedy', 'action', 'fantasy',
                                         'scifi']:
                movie_dict[year] = [title, category]
            else:
                print('Validation failed.')
    elif selection == 'p':
        print('{0:<10}{1:<45}{2:<10}'.format('Year', 'Movie Name', 'Category'))
        for year, values in movie_dict.items():
            print('{0:<10}{1:<45}{2:<10}'.format(year, values[0], values[1]))

    elif selection == 'pc':
        category = input("Please enter the desired category: ")
        print('{0:<10}{1:<45}{2:<10}'.format('Year', 'Movie Name', 'Category'))
        found = False
        for
year, values in movie_dict.items():
            if values[1] == category:
                print('{0:<10}{1:<45}{2:<10}'.format(year, values[0], values[1]))
                found = True
        if not
found:
            print('No matches')


    elif selection == 'q':
        break

Add a comment
Know the answer?
Add Answer to:
For Python 3.8! Copy and paste the following bolded code into IDLE: movies = [[1939, 'Gone...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • NOTE: I ONLY NEED THE CODE FOR THIS PART: "3 - add movie and category to...

    NOTE: I ONLY NEED THE CODE FOR THIS PART: "3 - add movie and category to list for an entered year". YOU DON'T HAVE TO GIVE ME THE CODE FOR MENU OPTIONS 1, 2, pc, p, OR q BECAUSE I HAVE THAT ALREADY. ONLY 3! EDIT: THIS IS FOR PYTHON 3.8. In this assignment you are to enhance the movie list display program from Assignment 4 to help maintain a list of movies that won the Academy Award (Oscar) for...

  • This homework problem has me pulling my hair out. We are working with text files in Java using Ne...

    This homework problem has me pulling my hair out. We are working with text files in Java using NetBeans GUI application. We're suppose to make a movie list and be able to pull up movies already in the text file (which I can do) and also be able to add and delete movies to and from the file (which is what I'm having trouble with). I've attached the specifications and the movie list if you need it. Any help would...

  • Need a program in python. Asterix and Obelix want to store and process information about movies...

    Need a program in python. Asterix and Obelix want to store and process information about movies they are interested in. So, you have been commissioned to write a program in Python to automate this. Since they are not very computer literate, your program must be easy for them to use. They want to store the information in a comma separated text file. Using this they would need to generate a report – see all items AND show a bar chart...

  • VERY URGENT*** THANK YOU IN ADVANCE: THIS IS THE CODE I HAVE GOTTEN SO FAR: PYTHON...

    VERY URGENT*** THANK YOU IN ADVANCE: THIS IS THE CODE I HAVE GOTTEN SO FAR: PYTHON This is a code that is supposed to help someone study/ practice for jeopardy. The two functions described below are required for this assignment. You may add other functions that you think are appropriate: menu() This function, which displays all the user options to the screen, prompt the user for their choice and returns their choice. This function will verify user input and ALWAYS...

  • Need help with this C++ assignment, please use comments so I can better understand your code...

    Need help with this C++ assignment, please use comments so I can better understand your code like comments above your function header explaining what the function does and the purpose of each variable. etc. Assignment: Write a C++ program that reads a text file containing a list of movies "Movie_entries.txt" . Each line in the file contains tile, director, genre, year released and running time of a specific movie. Each field is separated by comma. Print out movie titles sorted...

  • Need this in C++ Goals: Your task is to implement a binary search tree of linked...

    Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...

  • Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director,...

    Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures and perform the following operations: Search for a specific title Search for movies by a specific director Search for movies by a specific genre Search for movies released in a certain time period Search for movies within a range for running time Display the movies on the screen in a nice, easy to read...

  • Hello, In Python Enhance the prior assignment by doing the following 1) Create a class that...

    Hello, In Python Enhance the prior assignment by doing the following 1) Create a class that contain all prior functions MyLib # This function adds two numbers def addition(a, b): return a + b # This function subtracts two numbers def subtraction(a, b): return a - b # This function multiplies two numbers def multiplication(a, b): return a * b # This function divides two numbers # The ZeroDivisionError exception is raised when division or modulo by zero takes place...

  • Lab Exercise 5.2 Instructions: Name the program toMoviesYourLastNameFirstInitialLE52.java. The ...

    Lab Exercise 5.2 Instructions: Name the program toMoviesYourLastNameFirstInitialLE52.java. The only class variable will be for the Scanner class. setMovieTitle(): Prompts for the title of the movie, and returns it from the keyboard. setYearReleased(): Prompts for the year in which the movie was released, and returns it from the keyboard. setMovieGenre(): Prompts for the type or category of the movie: action, animation, comedy, crime, documentary, drama, and returns it from the keyboard. setTicketPrice(): Prompts for the price of a movie ticket,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT