""" pirple.com/python Python Homework Assignment #7: Dictionaries and Sets Details: Return to your first homework assignments, when you described your favorite song. Refactor that code so all the variables are held as dictionary keys and value. Then refactor your print statements so that it's a single loop that passes through each item in the dictionary and prints out it's key and then it's value. Extra Credit: Create a function that allows someone to guess the value of any key in the dictionary, and find out if they were right or wrong. This function should accept two parameters: Key and Value. If the key exists in the dictionary and that value is the correct value, then the function should return true. In all other cases, it should return false. """ # Song attributes dictionary song = { "title": "We Are the Champions", "album": "News of the World", "artist": "Queen", "genre": "Arena rock", "release year": "1977", "length": "2.59", "length (seconds)": "179", "songwriter": "Freddie Mercury", "producers": "Queen, Mike \"Clay\" Stone" } # Print the info aboute song for key in song: print("{0:s}: \"{1:s}\"".format(key.capitalize(), song[key])) def guess(key, val): return key in song and song[key] == val print("\n\nBonus:\n\n") print("Is the title of this song \"We Are the Champions\"?: {}".format( guess("title", "We Are the Champions"))) print("Is the album name \"News of the World\"?: {}".format( guess("album", "News of the World")))