Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this homework assignment, you are supposed to implement a playlist that contains multiple songs. In this playlist, for each song, you will store a

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
In this homework assignment, you are supposed to implement a playlist that contains multiple songs. In this playlist, for each song, you will store a record, in which you keep 1. The song title (string), 2. The year that the song is/was released (integer), 3. The name of the singer (the first and the last name as one string), and 4. Whether or not this song was liked by the user (a Boolean flag). For the sake of simplicity, you may assume that for each song, there is always one singer. The user will add and delete songs from this playlist. Additionally, the user may like a song at some point but unlike the same song later. Thus, in your implementation, you MUST define a list to keep information of each song and you MUST define a list of lists to keep the entire playlist. That is, you will use a list of lists (a playlist of songs where a song is also represented as a list). Clarification: Throughout the text, we will refer to the first list as a song list and the list of lists as the playlist. Your implementation must have at least the following seven functions whose details are given below: 1. Add a song 2. Remove a song 3. Like a song 4. Unlike a song 5. Display all songs in a playlist 6. Display all liked songs in a playlist 7. Show information about a particular song ADD A SONG This function adds a song to the playlist. The song title, the release year, and the singer's name are specified as parameters. The liked flag should be set to False by default; that is, each song should be considered as not-liked when it is added to the playlist. In this playlist, the song titles are unique. They are also case insensitive; that is, "feeling good" and "FEElinG gooD" should be considered as the same. Thus, if the user attempts to add a song with an already existing title, the function does not add the song to the playlist and displays a warning message. Otherwise, it performs the action. Note that there might be multiple songs of the same singer. (See the example test program and its corresponding output given below to better understand how this function should work and the format of the warning message.) For this function, you MUST use the following header. * This function takes a list of songs together with the title, the release year, * and the singer's name of the song to be added. The liked flag should be set to \# False by default. If the song title does not exist in the playlist, the function \# adds a song list, which keeps the information about the song, to the end of * the playlist. Otherwise, if the song title already exists in the playlist, the \# function does not add any song list to the playlist and displays a warning \# message (for the message format, see the output example of the test program \# given below). You may assume that the function arguments are always valid. \# That is, the title and the singer's name are always strings, and the release * year is always a positive integer. def add_song (playlist, title, year, singer): * Write your code here REMOVE A SONG This function removes a song from the playlist. The song title is specified as a parameter. If there is no song with the specified title, the function does not remove any song from the playlist and displays a warning message. Otherwise, it performs the action. (See the example test program and its corresponding output given below to better understand how this function should work and the format of the warning message.) For this function, you MUST use the following header. \# This function takes a list of songs (playlist) together with the title of a \# song to be removed. If the song title exists in the playlist, the function \# removes the corresponding song list from the playlist. Otherwise, if the song \# title does not exist in the playlist, the function does not remove any song \# from the playlist and displays a warning message (for the message format, see \# the output example of the test program given below). You may assume that the * song title argument is always a string. Remember that all song titles are \# unique and case insensitive. def remove_song(playlist, title): \# Write your code here \# ... LIKE A SONG This function is to like a song from the playlist. The song title is specified as a parameter. If there is no song with the specified title, the function does not like any song from the playlist and displays a warning message. Otherwise, it performs the action. Note that if the corresponding song has already been liked, this function will not change the like status of the song. (See the example test program and its corresponding output given below to better understand how this function should work and the format of the warning message.) For this function, you MUST use the following header. \# This function takes a list of songs (playlist) together with the title of a \# song to be liked. If the song title exists in the playlist, the function \# likes the corresponding song list in the playlist. Otherwise, if the song \# title does not exist in the playlist, the function does not like any song \# in the playlist and displays a warning message (for the message format, aee * the output example of the test program given below). You may assume that the * song title argument is always a string. Remember that all song titles are * unique and case insensitive. def like song(playlist, title): * Write your code here * UNLIKE A SONG This function is to unlike a song from the playlist. The song title is specified as a parameter. If there is no song with the specified title, the function does not like any song from the playlist and displays a warning message. Otherwise, it performs the action. Note that if the corresponding song has not been liked, this function will not change the like status of the song (i.e., its status should remain as unliked). (See the example test program and its corresponding output given below to better understand how this function should work and the format of the warning message.) For this function, you MUST use the following header. \# This function takes a list of songs (playlist) together with the title of a \# song to be unliked. If the song title exists in the playlist, the function \# unlikes the corresponding song list in the playlist. Otherwise, if the song \# title does not exist in the playlist, the function does not unlike any song \# in the playlist and displays a warning message (for the message format, see \# the output example of the test program given below). You may assume that the \# song title argument is always a string. Remember that all song titles are \# unique and case insensitive. def unlike song(playlist, title): * Write your code here \# ... DISPLAY ALL SONGS This function lists all songs already found in the playlist. The output should be in the following format. If there are no songs in the playlist, this function displays - EMPTY PLAYLIST-- (See the output example of the test program given below to better understand the format.) PLAYLIST title by singer name (for the 1st song) title by singer name (for the 2nd song) For this function, you MUST use the following header. * This function takes a list of songs (playlist) and displays all song lists * found in the playlist according to the required output format. If there exist * no songs in the playlist, this function displays - EMpTY-- (see the output * example of the test program given below). def display_a11_songs (playlist) : \# Write your code here DISPLAY ALL LIKED SONGS This function lists the songs in the playlist, which are currently liked by the user (i.e., the songs with a liked status). The output should be in the following format. If there are no liked songs in the playlist, this function displays --EMPTY LIKED PLAYLIST-- (See the output example of the test program given below to better understand the format.) LIKED SONGS title by singer name title by singer name (for the 1st liked song) (for the 2nd liked song) For this functicin, you MUST use the following header. \# This function takes a list of songs (playlist) and displays al1 liked songs \# in the playlist according to the required output format. If there exist \# no liked songs in the playlist, this function displays - -EMPTY-- (see the \# output example of the test program given below). def display_al1_liked_songs (playlist): \# Write your code here SHOW A SONG This function displays all information about a song whose title is specified as a parameter. The output should be in the following format. If the song with the specified title does not exist in the playlist, the function displays a warning message. (See the example test program and its corresponding output given below to better understand how this function should work and the format of the warning message.) Title of the song + if it is a liked song> Released in release year Performed by For this function, you MUST use the following header. \# This function takes a playlist together with the title of a song whose \# Information will be showed. If the song title exists in the play1lst, \# the function displays the information stored in the corresponding song 1ist * according to the required output format. If the title does not exist in the \# playlist, it displays a warning message (for the message format, see the output \# example of the test program given below). You may assume that the song title def show_song(playlist, title): \# Write your code here WHAT TO SUBMIT? This homework assignment asks you to submit only one file whose name must be playlist.py. This file should contain at least seven functions whose details are given above. Remember that the headers of these functions must be def add_song(playlist, title, year, singer): def remove_song(playlist, title): def like_song(playlist, title): def unlike_song (playlist, title): def display_all_songs(playlist): def display_all_liked_songs(playlist): def show_song(playlist, title): Your file may contain other auxiliary functions, which might be called from the aforementioned four functions. However, it SHOULD NOT contain a function whose name is main(). Additionally, this file SHOULD NOT have any statements written outside a function definition. We will test your functions writing our own main function, similar to the one given below, and calling this main function to start the program. ***IMPORTANT: You MUST use the given function headers as they are. We will use these headers to call your functions and test them. You are NOT allowed to modify these function headers. If you modify them, you will get no points from the corresponding part since we cannot call your functions properly, and thus, we cannot test and grade them. Additionally, if your file contains a function called main() or if it has a statement outside any function definition, you may lose a considerable number of points. Note that although you will not submit a main function, you should, of course, write a main function in another py file and test your own functions (but do not submit this additional py file). Please note that, the correctness of your program will, of course, affect your grade. However, in addition to this, the following points are important to get the full credit. - You MUST use meaningful names for the variables. - You MUST write explanatory and clearly understandable comments. - At the beginning of each file, you MUST write your name, your id, and your section as comments. After these, you MUST provide a very brief description about what the program does as additional comments. Here is an example test program, containing an example main function, and the corresponding output. We will use a similar program (but not exactly the same one) to test your functions so make sure that the name of your submitted file is playlist.py and you use the functions headers given above. This test program is just an example and may not test the program thoroughly. Thus, we strongly advise you to test your program for other uses. playlist.remove_song(L, 'Billie Jean') playlist.remove_song(L, 'Feeling Good') ') playlist.remove_song(L,' 'Sinnerman', ') The output of this test program should be: - EMPTY PLAYLIST-- PLAYLIST Feeling Good by Nina Simone Dance Monkey by Tones and I Sinnerman by Nina Simone Batsin Bu Dunya Batsin by --EMPTY PLAYLIST-- PLAYLIST Feeling Good by Nina Simone Dance Monkey by Tones and I Sinnerman by Nina Simone Batsin Bu Dunya Batsin by orhan Gencebay Bella Ciao by Manu Pilas Bang Bang by Nancy Sinatra (error in add) : Feeling Good already exists (error in add) : BElla CIAo already exists PLAYLIST Feeling Good by Nina Simone Dance Monkey by Tones and I Sinnerman by Nina Simone Batsin Bu Dunya Batsin by Orhan Gencebay Bella Ciao by Manu Pilas Bang Bang by Nancy Sinatra - EMPTY LIKED PLAYLIST-- LIKED SONGS Feeling Good by Nina Simone Batsin Bu Dunya Batsin by Orhan Gencebay Bella Ciao by Manu Pilas PLAYLIST Feeling Good by Nina Simone Dance Monkey by Tones and

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started