Question: Please write code in python For this lesson we are going to use both the range and enumeration functions to build song lyrics. Create build_lyrics
Please write code in python





For this lesson we are going to use both the range and enumeration functions to build song lyrics. Create build_lyrics Create a function named "build_lyrics' that has two parameters: a lyric word (could be a set of words too) repeat which is used to repeat the word The function returns a list of the word repeated repeat times you must use the range function The following should work: def test_lyric(): a = build_lyrics('I', 3) print(a) The test_lyric function should print ['I', 'I', 'I'] Create lyrics_to_string Create a function named lyrics_to_string whose parameter is a list of words (created via build_lyrics) builds a string that contains the full set of lyrics it must use the enumerate function you cannot use the join method add a space and a comma after each lyric For example: def test_lyrics(): a = build_lyrics('I', 3) b = build_lyrics('I Shake it off', 2) a_s = lyrics_to_string(a) b_s = lyrics_to_string(b) print(a_s) print(b_s) Should print: I, I, I, I Shake it off, I Shake it off, Sample Verse We can also use the same functions to build verses: def build_verse(): a = build_lyrics('I', 3) b build_lyrics('I Shake it off', 2) a_s = lyrics_to_string(a) b_s = lyrics_to_string(b) d = build_lyrics (a_s+b_s, 2) print(lyrics_to_string(d)) build_verse should print: I, I, I, I Shake it off, I Shake it off, I, I, I, I Shake it off, I Shake it off, 7 Extra Credit (+5 points) Fix lyrics_to_string such that the trailing commas are removed. The build_verse function should now show up as: I, I, I, I Shake it off, I Shake it off, I, I, I, I Shake it off, I Shake it off, Note that the space is still maintained. As a hint to this one, it's a matter of using all the great string methods you learned about in the previous lesson. No need to search for anything outside of what has already been shown. Sample Song (Extra Credit +10) For extra credit, create the function lyrics_to_song which works a lot like lyrics_to_string: it must use the enumerate function you can use join but not required see the example for how to format each line Note that the function build_lyrics does not change. def test song(): lyrics = build_lyrics (build_lyrics('I', 3) + build_lyrics('I Shake it off', 2), 3) song = lyrics_to_song(lyrics) print(song) The output should match what is shown below: 1: I, I, I, I Shake it off, I Shake it off 2: I, I, I, I Shake it off, I Shake it off 3: I, I, I, I Shake it off, I Shake it off
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
