Python Forum
Dictionary/List Homework
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary/List Homework
#13
I have a completely working program now with one exception. I can't seem to figure out where the indention error is coming from.
  File "C:/Users/brand/PycharmProjects/Test/Playground Two/.idea/Playground Two.py", line 38
    else:
    ^
IndentationError: expected an indented block

Process finished with exit code 1
movies = {2005: ['Munich', 'Steven Spielberg'],
        2006: ['The Prestige', 'Christopher Nolan','The Departed', 'Martin Scorsese'],
        2007: ['Into the Wild', 'Sean Penn'],
        2008: ['The Dark Knight', 'Christopher Nolan'],
        2009: ['Mary and Max', 'Adam Elliot'],
        2010: ['The King\'s Speech', 'Tom Hooper'],
        2011: ['The Artist', 'Michel Hazanavicius', 'The Help', 'Tate Taylor'],
        2012: ['Argo', 'Ben Affleck'],
        2013: ['12 Years a Slave', 'Steve McQueen'],
        2014: ['Birdman', 'Alejandro G. Inarritu'],
        2015: ['Spotlight', 'Tom McCarthy'],
        2016: ['The BFG', 'Steven Spielberg']}
# Prompt the user for a year
year = int(input())
print('Enter a year between 2005 and 2016:')

# Displaying the title(s) and directors(s) from that year
if year == 2005:
    print(movies[year][0]+', '+movies[year][1])
elif year == 2006:
    print(movies[year][0]+', '+movies[year][1]+'\n'+movies[year][2]+', '+movies[year][3])
elif year in range(2007,2010):
    print(movies[year][0]+', '+movies[year][1])
elif year == 2011:
   print(movies[year][0]+', '+movies[year][1]+'\n'+movies[year][2]+', '+movies[year][3])
elif year in range(2012, 2017):
    print(movies[year][0]+', '+movies[year][1])
else:
    print('N/A')
# Display menu

#MENU
options = input()
while options != 'q':
    if options != 'q' or 't' or 'd' or 'y':
        while options != 'q' or 'd' or 't' or 'y':
    else:
        if options == 'q':
            print('\nMENU\nSort by:\ny - Year\nd - Director\nt - Movie title\nq - Quit')
            print('\nChoose an option:')
        if options == 'y':
            print('\nMENU\nSort by:\ny - Year\nd - Director\nt - Movie title\nq - Quit')
            print('\nChoose an option:')
            for key in movies:
                print('%s:'% key)
                i = 0
                while i < len(movies[key]):
                    print('\t%s, %s'% (movies[key][i],movies[key][i +1]))
                    i += 2
                print()
        director_list = []
        if options == 'd':
            print('\nMENU\nSort by:\ny - Year\nd - Director\nt - Movie title\nq - Quit')
            print('\nChoose an option:')
            for key in movies:
                i = 1
                while i < len(movies[key]):
                    director_list.append(movies[key][i])
                    i += 2
            set_director = sorted(set(director_list))
            for director in set_director:
                print('%s:' % director)
                for year, value in sorted(movies.items()):
                    if director in value:
                        print('\t%s, %s' % (value[value.index(director) - 1], year))
                print()
        title_list = []
        if options == 't':
            print('\nMENU\nSort by:\ny - Year\nd - Director\nt - Movie title\nq - Quit')
            print('\nChoose an option:')
            for key in movies:
                i = 0
                while i < len(movies[key]):
                    title_list.append(movies[key][i])
                    i += 2
            set_title = sorted(set(title_list))
            for title in set_title:
                print('%s:' % title)
                for year, value in sorted(movies.items()):
                    if title in value:
                        print('\t%s, %s' % (value[value.index(title)+1], year))
                print()
Reply


Messages In This Thread
Dictionary/List Homework - by ImLearningPython - Dec-12-2018, 12:13 AM
RE: Dictionary/List Homework - by DeaD_EyE - Dec-12-2018, 09:25 AM
RE: Dictionary/List Homework - by ImLearningPython - Dec-12-2018, 12:49 PM
RE: Dictionary/List Homework - by ImLearningPython - Dec-12-2018, 04:44 PM
RE: Dictionary/List Homework - by woooee - Dec-12-2018, 05:31 PM
RE: Dictionary/List Homework - by ImLearningPython - Dec-12-2018, 08:04 PM
RE: Dictionary/List Homework - by woooee - Dec-12-2018, 08:37 PM
RE: Dictionary/List Homework - by ImLearningPython - Dec-12-2018, 08:41 PM
RE: Dictionary/List Homework - by nilamo - Dec-12-2018, 08:41 PM
RE: Dictionary/List Homework - by woooee - Dec-13-2018, 04:19 PM
RE: Dictionary/List Homework - by ImLearningPython - Dec-13-2018, 05:42 PM
RE: Dictionary/List Homework - by nilamo - Dec-13-2018, 06:15 PM
RE: Dictionary/List Homework - by ImLearningPython - Dec-14-2018, 02:53 PM
RE: Dictionary/List Homework - by ichabod801 - Dec-14-2018, 03:06 PM
RE: Dictionary/List Homework - by nilamo - Dec-14-2018, 03:45 PM
RE: Dictionary/List Homework - by ImLearningPython - Dec-14-2018, 04:32 PM
RE: Dictionary/List Homework - by ichabod801 - Dec-14-2018, 04:40 PM
RE: Dictionary/List Homework - by ImLearningPython - Dec-14-2018, 06:41 PM
RE: Dictionary/List Homework - by ImLearningPython - Dec-14-2018, 09:33 PM
RE: Dictionary/List Homework - by ichabod801 - Dec-14-2018, 09:38 PM
RE: Dictionary/List Homework - by ImLearningPython - Dec-14-2018, 09:49 PM
RE: Dictionary/List Homework - by ichabod801 - Dec-14-2018, 09:54 PM
RE: Dictionary/List Homework - by ImLearningPython - Dec-17-2018, 12:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with list homework eyal123 5 1,756 Nov-18-2022, 03:46 PM
Last Post: deanhystad
  Homework - List containing tuples containing dicti Men 4 2,086 Dec-28-2021, 12:37 AM
Last Post: Men
  Sorting list - Homework assigment ranbarr 1 2,283 May-16-2021, 04:45 PM
Last Post: Yoriz
  Loop through elements of list and include as value in the dictionary Rupini 3 2,706 Jun-13-2020, 05:43 AM
Last Post: buran
  How can details be dynamically entered into a list and displayed using a dictionary? Pranav 5 2,988 Mar-02-2020, 10:17 AM
Last Post: buran
  Functions returns content of dictionary as sorted list kyletremblay15 1 2,086 Nov-21-2019, 10:06 PM
Last Post: ichabod801
  have homework to add a list to a list using append. celtickodiak 2 2,073 Oct-11-2019, 12:35 PM
Last Post: ibreeden
  Dictionary Homework beepBoop123 3 2,674 Dec-11-2018, 10:00 PM
Last Post: buran
  making a dictionary from a list, one key with multiple values in a list within a list rhai 4 3,678 Oct-24-2018, 06:40 PM
Last Post: LeSchakal
  Need some help with list and dictionary .txt GeekLife97 3 3,886 Jan-20-2017, 08:00 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020