1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Fynjy0 [20]
3 years ago
3

The following example demonstrates a program that uses 3 levels of nested dictionaries to create a simple music library. The fol

lowing program uses nested dictionaries to store a small music library. Extend the program such that a user can add artists, albums, and songs to the library. First, add a command that adds an artist name to the music dictionary. Then add commands for adding albums and songs. Take care to check that an artist exists in the dictionary before adding an album, and that an album exists before adding a song.
music = {
'Pink Floyd': {
'The Dark Side of the Moon': {
'songs': [ 'Speak to Me', 'Breathe', 'On the Run', 'Money'],
'year': 1973,
'platinum': True
},
'The Wall': {
'songs': [ 'Another Brick in the Wall', 'Mother', 'Hey you'],
'year': 1979,
'platinum': True
}
},
'Justin Bieber': {
'My World':{
'songs': ['One Time', 'Bigger', 'Love Me'],
'year': 2010,
'platinum': True
}
}
}

#complete/edit code given below:

# Get user input

# While user input != 'exit'
# ...
Computers and Technology
1 answer:
patriot [66]3 years ago
4 0

Answer:

def add_album(artist,album):

   song_list = input("enter the list of song titles separated by comma: ").split(",")

   print(song_list)

   year = int(input("enter release year: "))

   is_platinum = bool(input("Is it platinum? True/False"))

   music[artist][album] = {}

   music[artist][album]['songs'] = song_list

   music[artist][album]['year'] = year

   music[artist][album]['platinum'] = is_platinum

def add_artist():

   artist = input("enter name of artist: ")

   if music.get(artist, "no") == "no":

       music[artist] = {}

       

   else:

       print("artist already exist in dictionary.")

   is_album = input("add album? ")

   if is_album == "yes":

       album_name = input("Enter album name: ")

       add_album(artist,album_name)

           

for _ in iter(dict, 0):

   is_exist = input("Do you want to end the program? yes/no: ")

   if is_exist == "yes":

       break

   elif is_exist == "no":

       is_art = input("Add artist? ")

       if is_art == "yes":

           add_artist()

       else:

           print("enter  yes/no")

   else:

       print("make a decision, yes/no")

Explanation:

The python program defines an "add_artist" and "add_album" function that references the dictionary "music". The functions prompt for user inputs of the artist name, album, year, and platinum record.

The functions use the bracket notation to access and update the dictionary in the memory.

You might be interested in
The involvement of the United States in the ______ and ______ resulted in _______ .
Aleksandr-060686 [28]

The involvement of the United States in the <u>Iraq</u> and <u>Kuwait conflict</u> resulted in <u>Persian Gulf War</u>.

<h3>What is the Persian Gulf War?</h3>

The Persian Gulf War can be defined as an international conflict that was led by the United States of America alongside the forces of the United Nations (UN) against the larger state of Iraq, in response to her invasion and annexation of the smaller country of Kuwait.

In this context, we can infer and logically deduce that the involvement of the United States in the <u>Iraq</u> and <u>Kuwait conflict</u> resulted in <u>Persian Gulf War</u>.

Read more on Persian Gulf War here: brainly.com/question/1105731

#SPJ1

8 0
3 years ago
Do opportunity costs only occur when making spending decisions
Naily [24]

Answer:

yes there is opportunity in every thing such as do i buy this car what am i going to miss out on if i buy this what does this offer

Explanation:

6 0
3 years ago
Where would you go to access frequently used icons?
trapecia [35]

Answer:

b

Explanation:

4 0
3 years ago
Read 2 more answers
Describe a strategy that you could use to win the recess basketball shooting game HORSE. Analyze your strategy’s risks and rewar
kobusy [5.1K]

Answer:

i mean, theres not much strategy to the game at all, its just being able to shoot from hard spots, and obviously have good consistentsy

Explanation:

5 0
4 years ago
A direct link between a single ____ preserves the fine details in the cones message
son4ous [18]
A single bipolar cell....
 your answer !!

6 0
3 years ago
Other questions:
  • Consider the binary search tree constructed for the words oenology, phrenology, campanology, ornithology, ichthyology, limnology
    14·1 answer
  • Is a display, or monitor, considered a piece of computer hardware
    15·1 answer
  • A. True
    5·1 answer
  • What is the name of the subsystem that transfers data between components inside a pc or between pcs?
    12·1 answer
  • The 2 main types of copyright relevant to the recording industry?
    5·2 answers
  • Type two statements.
    11·1 answer
  • Hosts A and B are 20 000 km away from each other. The propagation speed of the link between them is 25000 mps. The data is place
    9·1 answer
  • EMERGENCYYYYY what does it mean when i get a security alert when i download an addon on google docs
    7·1 answer
  • What is the purpose of using variables in programming?
    11·1 answer
  • How is unqualified assumptions a disadvantage of communication​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!