Oct-26-2019, 02:41 PM
Cheers! I'm a self-learning beginner using a crash course book. One of the "Try It Yourself" at the end of the chapter has me create a function with a while loop that prompts for your record. At the end you should be able to print the dictionary.
It works fine until I add a break statement. It inserts the "q" response as one of the values in the dictionary.
It works fine until I add a break statement. It inserts the "q" response as one of the values in the dictionary.
# This is the definition def make_album(artist, album, tracks=''): """Return a dictionary of artist album info""" music = { 'artist': artist, 'album': album, } if tracks: music['tracks'] = tracks return music # This is the while Loop while True: print("\nPlease tell me your favorite band and record.") print("(Enter 'q' at any time to quit)") b_name = input("Band name: ") if b_name == 'q': break a_name = input("Album name: ") if a_name == 'q': break record = make_album(b_name, a_name) print(record)
Output:Please tell me your favorite band and record.
(Enter 'q' at any time to quit)
Band name: the cult
Album name: electric
Please tell me your favorite band and record.
(Enter 'q' at any time to quit)
Band name: q
{'artist': 'q', 'album': 'electric'}