Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Download the ICStunes program (http://www.ics.uci.edu/~harris/python/ICStunes0.p

ID: 666663 • Letter: D

Question

Download the ICStunes program (http://www.ics.uci.edu/~harris/python/ICStunes0.py) on the lab machine (or whatever machine you and your partner are using) and run it to make sure it works. As you work on this part, make your changes in (copies of) the ICStunes.py file you downloaded; use your lab8.py file for the other parts of this assignment.

(1) Write a function called Song_str that takes a song and returns a string containing that song's information in an easily readable format suitable for printing. You may choose the exact layout

Then write a function called Album_str that takes an album and returns a string containing that album's information (including the Song_str information for each song on the album) in an easily readable format suitable for printing.

Test your functions by printing a couple of the sorted collections from the first part of the ICStunes file.

Finally, write a function called Songdisplay_str that takes a Songdisplay and returns a string containing that information in an easily readable form suitable for printing. Test it using the results of top_n_played (located at the bottom of the ICStunes file).

(2) As we did previously with the albums' year, title, length, and ID, write a key function and a call to the sort() method to sort the collection MUSIC by the number of tracks on each album, lowest to highest; then print the resulting collection using Album_str.

Next, sort the collection MUSIC by some other key to rearrange it. Then perform the number-oftracks sorting task by calling collection_sort and then printing the resulting sorted collection

(3) Write a function called unplayed_songs that takes a music collection (a list of albums) and returns a list of Songdisplays, one for each song that has never been played. Print the resulting list using Songdisplay_str. [Please note: At this point it should be clear to everyone that the print statement does not go inside the unplayed_songs function. That function, as specified above, returns a list of Songdisplays; you print that result in the calling program—where you call the function. That's what this problem specifies.]

(4) Write a function called length_from_songdisplay that takes a Songdisplay and returns the length of the song. (This is quick and easy.)

(5) Write a function called favorite_album that takes a list of albums and returns the album that is the "favorite." We'll define the favorite album as the one that the user has spent the most time listening to. [The total time the user has spent listening to an album is computed from the play counts and the song lengths.]

Figure out by hand which album in the collection MUSIC has the greatest listening time (it's okay to collaborate with your classmates outside of your partnership on this specific fact); then print (using Album_str, of course) the result of calling favorite_album on the collection MUSIC and see if it matches. [Hint: Songdisplays aren't involved in this part.]

(6) Generalize the top_n_played function (i.e, make it apply to a broader range of criteria than just play counts) as follows: Write a function called top_n that takes a list of albums and a number, as before, plus two additional parameters—(the name of) a function we can use as a sort key for comparing albums and a Boolean (that's true if you want the n highest values and false if you want the n lowest). Thus, you could use the new top_n to produce the same result as top_n_played by calling

top_n(MUSIC, 3, play_count_from_songdisplay, True)

and you could use it to produce the 10 shortest songs by calling

top_n(MUSIC, 10, length_from_songdisplay, False)

(7) Total listening time isn't the only way of determining a favorite album. Generalize your favorite_album function by writing a function called favorite_album2 that takes a list of albums and a second argument—a "favorite measurement function" that favorite_album2 can apply to each album, comparing those results to determine the favorite. This call to favorite_album2 would behave the same way as a call to the original favorite_album function:

favorite_album2(MUSIC, Album_listening_time)

Write at least one example of a favorite measurement function other than total listening time. Then test your favorite_album2 function by applying that new function. [Hint: Songdisplays aren't involved in this part.]

(8) Music manager programs typically provide a search box into which you can type a keyword; the program then searches your collection for songs containing that keyword in their title, their artist, or their album's title. Write a function called collection_search that behaves in the same way, taking a collection and a string as parameters and returning a list of Songdisplays of songs whose title, artist, or album title include that string.

Explanation / Answer

def Song_str(s: Song) -> 'list of song details':
   result=[ ]
   result.append(s.track, s.title, s.length, s.play_count)
   return result
def Album_str(a: Album) -> 'list of album details':
   result=[]
   result.append(a.artist, a.title, a.year)
   for s in a.songs:
       result.append(s.track, s.title, s.length, s.play_count)
   return result
def Songdisplay_str(sd: Songdisplay) -> 'list of Songdisplay details':
   result=[]
   result.append(sd.artist,sd.a_title,sd.year,sd.track,sd.s_title,sd.length,sd.play_count)
   return result
def SortAlbum() -> 'list of song':
   Songlist = all_songs(MUSIC)
   Songlist.sort(key=Album_title)
   return Songlist

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote