Answer the question
In order to leave comments, you need to log in
How to store data in a python dictionary?
Hello!
I'm doing the next activity:
User Albums: Start with your program from Exercise 8-7. Write a while loop that allows users to enter an artist name and an album name. Once you have this information, call make_album() with user input and print the generated dictionary. Don't forget to include the exit value in the while loop.
my code:
active = True
while active:
album = {}
name = input()
track_name = input()
album[name] = track_name
if name == 'q':
break
def make_album(album):
return album
print(make_album(album))
def make_album(group, name_track, count_tr=None):
if count_tr:
album = {}
album['group'] = group
album['name_track'] = name_track
album['count'] = count_tr
return album
else:
album = {}
album['group'] = group
album['name_track'] = name_track
return album
print(make_album('scriptonit', 'animals', 24))
print(make_album('limp bizkit', 'golden cobra'))
print(make_album('max korzh', 'stilevo', 12))
Answer the question
In order to leave comments, you need to log in
It's not entirely clear what you want.
If you want to save the result of the make_album function (i.e. save the dictionary that this function returns), then simply write the function call to a variable. Thus, you will store the result of the function in this variable.
album_1 = make_album('limp bizkit', 'golden cobra')
album_2 = make_album('limp bizkit', 'take a look around')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question