Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi I need help to do this project I am very close but it said that there spaces

ID: 3707725 • Letter: H

Question

Hi I need help to do this project I am very close but it said that there spaces between the movie and the year and a tab instead of spaces between them can someone please help me to fix this corrrectlyy it is for lab on zybooks thank you.

Program: Sorting movies (Lists and Dictionaries) (Python 3)

(1) Build a dictionary that contains the movie collection below. Hint: Combine movie title and director into a list.

(2) Prompt the user for a single year and output the movie title(s) and director(s) from that year. Output N/A if the year is invalid. (4 pts)

Ex:

(3) After prompting the user for a year and displaying the title(s) and directors(s) from that year, display a menu. The menu enables a user to display the movies sorted by year, director, or movie title. Each option is represented by a single character.

The program initially outputs the menu, and outputs the menu after a user chooses an option. If an invalid character is entered, continue to prompt for a valid choice. The program ends when the user chooses the option to Quit. Hint: Implement Quit before implementing other options. For this step, the other options do nothing. (1 pt)

Ex:

(4) Implement the sort by year menu option. Note: There is a newline and a tab between the year and the movie title/director. (2 pts)

Ex:

(5) Implement the sort by director menu option. For directors with multiple films on the list, order their films by year. Note: There is a newline and a tab between the director's name and the movie title/year. (3 pts)

Ex:

(6) Implement the sort by movie title menu option. Note: There is a newline and a tab between the movie title and the movie director/year. (2 pts)

Ex:

movieCollectionDict = {"Munich":[2005, "Steven Spielberg"],
                       "The Prestige": [2006, "Christopher Nolan"],
                       "The Departed": [2006, "Martin Scorsese"],
                       "Into the Wild": [2007, "Sean Penn"],
                       "The Dark Knight": [2008, "Christopher Nolan"],
                       "Mary and Max": [2009, "Adam Elliot"],
                       "The King's Speech": [2010, "Tom Hooper"],
                       "The Artist": [2011, "Michel Hazanavicius"],
                       "The Help": [2011, "Tate Taylor"],
                       "Argo": [2012, "Ben Affleck"],
                       "12 Years a Slave": [2013, "Steve McQueen"],
                       "Birdman": [2014, "Alejandro G. Inarritu"],
                       "Spotlight": [2015, "Tom McCarthy"],
                       "The BFG": [2016, "Steven Spielberg"]
                       }

# Prompt the user for a year
# Displaying the title(s) and directors(s) from that year
promptForGivenYear = True
while promptForGivenYear:
    userchoiceOfMovie = int(input(" Enter a year between 2005 and 2016: "))

    if userchoiceOfMovie < 2005 or userchoiceOfMovie > 2016:
        print("N/A")
    
    else:
        for key, value in movieCollectionDict.items():
            if value[0] == userchoiceOfMovie:
                print(key + ", " + str(value[1]))
          
    promptForGivenYear = False
   
# Display menu

menu = " MENU"
       " Sort by:"
       " y - Year"
       " d - Director"
       " t - Movie title"
       " q - Quit"

# Carry out the desired option: Display movies by year,
# display movies by director, display movies by movie title, or quit

userchoiceOfMovie = True

while userchoiceOfMovie:
    print(menu)

    userChoice = str(input(" Choose an option: "))
  
    if userChoice == "q":
        userchoiceOfMovie = False
    elif userChoice == "y":
        year_sorted = {}
        for key, value in sorted(movieCollectionDict.items(), key=lambda item: (item[1], item[0])):
            year = value[0]
            title = key
            director = value[1]
            if year not in year_sorted:
                year_sorted[year] = [[title, director]]
            else:
                year_sorted[year].append([title, director])
        for year in sorted(year_sorted):
            print (str(year) + ":")
            movies = year_sorted[year]
            for movie in sorted(movies, key=lambda x: x[0]):
                print(" " + movie[0] + "," + movie[1])
              
    elif userChoice == "d":
        director_sorted = {}
        for key, value in sorted(movieCollectionDict.items(), key=lambda item: (item[1][1])):
            year = value[0]
            title = key
            director = value[1]
            if director not in director_sorted:
                director_sorted[director] = [[title, year]]
            else:
                director_sorted[director].append([title, year])
        for director in sorted(director_sorted):
            print (str(director) + ":")
          
            movies = director_sorted[director]
            for movie in sorted(movies, key=lambda x: x[0]):
                print("menu" + movie[0] + ", " + str(movie[1]))

    elif userChoice == "t":
        for key, value in sorted(movieCollectionDict.items(), key=lambda item: (item[0], item[1])):
            print(str(key) + ":")
            print(" " + str(value[1]) + ", " + str(value[0]) + " ")
    else:
        print("Invalid response")

Please fix it nicely and you can change anything you want in this program thank you

Explanation / Answer

movieCollectionDict = {"Munich":[2005, "Steven Spielberg"],
                       "The Prestige": [2006, "Christopher Nolan"],
                       "The Departed": [2006, "Martin Scorsese"],
                       "Into the Wild": [2007, "Sean Penn"],
                       "The Dark Knight": [2008, "Christopher Nolan"],
                       "Mary and Max": [2009, "Adam Elliot"],
                       "The King's Speech": [2010, "Tom Hooper"],
                       "The Artist": [2011, "Michel Hazanavicius"],
                       "The Help": [2011, "Tate Taylor"],
                       "Argo": [2012, "Ben Affleck"],
                       "12 Years a Slave": [2013, "Steve McQueen"],
                       "Birdman": [2014, "Alejandro G. Inarritu"],
                       "Spotlight": [2015, "Tom McCarthy"],
                       "The BFG": [2016, "Steven Spielberg"]
                       }

# Prompt the user for a year
# Displaying the title(s) and directors(s) from that year
promptForGivenYear = True
while promptForGivenYear:
    userchoiceOfMovie = int(input(" Enter a year between 2005 and 2016: "))

    if userchoiceOfMovie < 2005 or userchoiceOfMovie > 2016:
        print("N/A")

    else:
        for key, value in movieCollectionDict.items():
            if value[0] == userchoiceOfMovie:
                print(key + ", " + str(value[1]))

    promptForGivenYear = False

# Display menu

menu = " MENU"
       " Sort by:"
       " y - Year"
       " d - Director"
       " t - Movie title"
       " q - Quit"

# Carry out the desired option: Display movies by year,
# display movies by director, display movies by movie title, or quit

userchoiceOfMovie = True

while userchoiceOfMovie:
    print(menu)

    userChoice = str(input(" Choose an option: "))

    if userChoice == "q":
        userchoiceOfMovie = False
    elif userChoice == "y":
        year_sorted = {}
        for key, value in sorted(movieCollectionDict.items(), key=lambda item: (item[1], item[0])):
            year = value[0]
            title = key
            director = value[1]
            if year not in year_sorted:
                year_sorted[year] = [[title, director]]
            else:
                year_sorted[year].append([title, director])
        for year in sorted(year_sorted):
            print (str(year) + ":")
            movies = year_sorted[year]
            for movie in sorted(movies, key=lambda x: x[0]):
                # print(" " + movie[0] + "," + movie[1])
                print(" " + movie[0] + "," + movie[1])
            print()

    elif userChoice == "d":
        director_sorted = {}
        for key, value in sorted(movieCollectionDict.items(), key=lambda item: (item[1][1])):
            year = value[0]
            title = key
            director = value[1]
            if director not in director_sorted:
                director_sorted[director] = [[title, year]]
            else:
                director_sorted[director].append([title, year])
        for director in sorted(director_sorted):
            print (str(director) + ":")

            movies = director_sorted[director]
            for movie in sorted(movies, key=lambda x: x[0]):
                # print("menu" + movie[0] + ", " + str(movie[1]))
                print(" " + movie[0] + ", " + str(movie[1]))
            print()

    elif userChoice == "t":
        for key, value in sorted(movieCollectionDict.items(), key=lambda item: (item[0], item[1])):
            print(str(key) + ":")
            # print(" " + str(value[1]) + ", " + str(value[0]) + " ")
            print(" " + str(value[1]) + ", " + str(value[0]))
            print()
    else:
        print("Invalid response")