Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you paraphrase this code without changing the functions? def check_song(playlist,title): this is a basic auxiliary search function to check whether the song is present

can you paraphrase this code without changing the functions?

def check_song(playlist,title):

"""this is a basic auxiliary search function to check whether the song is present int the playlist or

or not, if they are, it would return the index of the song in the playlist with found

set to True else False"""

index=-1

found=False

if len(playlist)>0:

for i in playlist:

index+=1

#we using casefold function here to override the possibility of input title as case sensitive

if title.casefold() == i[0].casefold():

found=True

break

else:

pass

return [index,found]

def add_song(playlist, title,year,singer):

"""performed as per the instructions given in the question, used the

check_song function to find if duplicate exists, if yes, then the

error prompt else, add the song with its attribute to the playlist"""

index,found=check_song(playlist,title)

if not found:

if year>0 and isinstance(year,int):

if isinstance(singer,str):

playlist.append([title,year,singer,False])

else:

print(f"(error in add): enter {singer} in correct format ")

else:

print(f"(error in add): enter {year} in correct format ")

else:

print(f"(error in add): {title} already exists")

return playlist

def remove_song(playlist,title):

"""performed as per the instructions in the question,

used check_song function to see if the song is present in

the playlist or not, if no then the error prompt else,

remove the song with its data from the playlist"""

index,found=check_song(playlist,title)

if found:

del playlist[index]

else:

print(f"(error in remove): {title} is not in the playlist")

return playlist

def like_song(playlist,title):

"""simply used check_song function to find the song,

if song is present in the playlist then i set the song like_status

to True else give the error prompt"""

index,found=check_song(playlist,title)

if found:

playlist[index][3]=True

else:

print(f"(error in liking): {title} is not in the playlist")

return playlist

def unlike_song(playlist,title):

"""simply used check_song function to find the song,

if song is present in the playlist then i set the song like_status

to False else give the error prompt"""

index,found=check_song(playlist,title)

if found:

playlist[index][3]=False

else:

print(f"(error in disliking): {title} is not in the playlist")

return playlist

def display_all_songs(playlist):

"""programmed as per the instructions provided in the question,

i check if the length of the playlist is 0 , that means its an empty list/playlist

else, i use a for loop to iterate every element/song and print them with their singer"""

if len(playlist)==0:

print("--EMPTY PLAYLIST--")

else:

print("PLAYLIST")

for i in playlist:

print(f"{i[0]} by {i[2]}")

def display_all_liked_songs(playlist):

"""here i searched for every song with like_status set to True

and saved them in another list named "liked"

and checked if the length of the list is 0

that means, there is no liked song on the playlist,

else i print the "liked" list"""

liked=[]

for i in playlist:

if i[3]==True:

liked.append(i)

if len(liked)==0:

print("--EMPTY LIKED PLAYLIST--")

else:

print("LIKED SONGS")

for i in liked:

print(f"{i[0]} by {i[2]}")

def show_song(playlist,title):

"""i followed the same instructions as provided in the question, using the

check_song function to get the index of the song, it was neccessary to

check if the song is a liked song or not"""

ret=check_song(playlist,title)

index=ret[0]

if ret[1]:

if playlist[index][3]:

print(f"{title} +")

else:

print(f"{title}")

print(f"Released in {playlist[index][1]}")

print(f"Performed by {playlist[index][2]}")

else:

print(f"(error in showing): {title} is not in the playlist")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions

Question

Define a companys operating cycle.

Answered: 1 week ago