"""File: movie_d_use.py Purpose: Store information on a single movie as a Python dictionary Run: python movie_d.py Input: Title, Year, Director, Stars, and Rating of movie Ouput: The input information Note: In this version the title of the movie is passed to create_movie_d """ #---------------------------------------------------------------------- def create_stars(): """Get a list of stars from the user and return this""" stars = [] print "Enter the stars (empty line to stop)" star = raw_input(" ") while star != "": stars.append(star) star = raw_input(" ") return stars #---------------------------------------------------------------------- def create_movie_d(title): """Store information on a movie as a dictionary""" new_movie_d = dict() new_movie_d["Title"] = title year = int(raw_input("What's the year?\n ")) new_movie_d["Year"] = year director = raw_input("Who's the director?\n ") new_movie_d["Director"] = director stars = create_stars() new_movie_d["Stars"] = stars rating = int(raw_input("Rating?\n ")) new_movie_d["Rating"] = rating return new_movie_d #---------------------------------------------------------------------- def print_movie_d(movie_d): """Print info on a movie that's stored as a dictionary""" print print "Movie:" print " Title: ", movie_d["Title"] print " Year: ", movie_d["Year"] print " Director: ", movie_d["Director"] print " Stars: " for s in movie_d["Stars"]: print " ", s print " Rating: ", movie_d["Rating"] #---------------------------------------------------------------------- # Main program # Only execute the main program if this file is *not* imported into another if __name__ == "__main__": movie_d = create_movie_d("Avatar") print_movie_d(movie_d)