Question: Create a new class for songs Start by creating a class called Song with the following attributes: title: a string representing the song title length:
Create a new class for songs
Start by creating a class called Song with the following attributes:
title: a string representing the song title
length: a string representing the length of the song
A magic function that allows you to print a string representation of the song as shown below
Title: title
Length: length s the s stands for seconds
Create an album class
An album is a collection of songs. Make a class called Album that has the following characteristics:
title: a string representing the album title
songs: a list of Song objects within the album
artist: a string representing the artist name
year: an integer representation of the album release year
A function that allows you to print a string representation of the album as shown below
Title: album title
Artist: artist
Year: year
Songs: print each song on the album
Magic functions for mathematical comparisons based on year for sorting purposes. This can be accomplished with a single function or multiple see documentation
Create an artist class
An artist is a collection of songs. Make a class called Artist that has the following characteristics:
name: a string representing the artist name
discography: a list of Album objects made by this artist
A function that sorts the artist's albums by year
A function that allows you to print a string representation of the artist as shown below
Artist: artist
Albums: print each album sorted by year
Add a batch of data into the new structures
The file musicdata.json contains a batch of music data. JSON files are structured similarly to dictionaries and are used for many purposes like configuration files, for example The cell below uses the builtin json Python library to read the file in as a dictionary. The keys are artist names Taylor Swift", "Drake", BTS and each key will return a list of dictionaries, each an album, that have title, year, and songs keys, the latter returning another list of dictionaries containing the title and length in seconds of each song. Here is a summary of how the data are formatted:
artist name:
title: album title,
year: year,
songs:
title: song title,
length: length
import json
with openmusicdata.json', r as f:
artistdict json.loadf
Create one or more functions that add these data to each of the data structures you have created.
Finally, print any artist's discography and the track list for one of their albums
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
