← 返回 rippling 的题目列表Design a Spotify-like Class
类型:online_judge
Design a class to simulate a music application similar to Spotify. You need to implement the following methods:
add_song(song_name): Adds a new song to the playlist.
play_song(song_name): Plays the specified song. It should return the name of the song currently being played.
print_playlist_summary(): Prints and returns the number of songs in the current playlist and all song names.
Ensure methods can be invoked, and provide no less than five test cases. Consider edge cases such as duplicate song addition and playing songs not in the playlist.
Input/Output
Define your methods as follows:
add_song(song_name)
Input: song_name is a string that represents the name of the song to be added.
Output: No direct output, but the song should be added to the playlist.
play_song(song_name)
Input: song_name is a string that represents the name of the song to be played.
Output: If the song is in the playlist, return the song name; otherwise, return the string 'Song not found'.
print_playlist_summary()
Input: None
Output: Return a string in the format 'Total Songs: {count}, Playlist: {song1}, {song2}, ...' showing the number of songs in the current playlist and the song names.
Example
Input
add_song('Song1')