Question: playlist = [ ] def display _ menu ( ) : print ( Menu: ) print ( 1 . Add a song

playlist =[]
def display_menu():
print("Menu:")
print("1. Add a song")
print("2. Remove a song")
print("3. View playlist")
print("4. Number of songs")
print("5. Most frequently added song")
print("6. Exit")
while True:
display_menu()
choice = input("Enter your choice (1-6): ")
if choice =='1':
song = input("Enter the name of the song to add: ")
playlist.append(song)
print(f"'{song}' has been added to the playlist.")
elif choice =='2':
song = input("Enter the name of the song to remove: ")
if song in playlist:
playlist.remove(song)
print(f"'{song}' has been removed from the playlist.")
else:
print(f"'{song}' is not in the playlist.")
elif choice =='3':
if playlist:
print("Your playlist:")
for idx, song in enumerate(playlist,1):
print(f"{idx}.{song}")
else:
print("The playlist is empty.")
elif choice =='4':
print(f"There are {len(playlist)} songs in the playlist.")
elif choice =='5':
if playlist:
most_frequent = max(set(playlist), key=playlist.count)
count = playlist.count(most_frequent)
print(f"The most frequently added song is '{most_frequent}'(added {count} times).")
else:
print("The playlist is empty.")
elif choice =='6':
print("Thank you for using the Music Playlist Manager. Goodbye!")
break
else:
print("Invalid choice. Please select a number from 1 to 6.")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!