Question: Please write code in python Create build_lyrics Create a function named build_lyrics' that has two parameters: a lyric word (could be a set of words

Please write code in python

Please write code in python 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 functionreturns a list of the word repeated repeat times you must usethe range function The following should work: def test_lyric(): a = build_lyrics('I',

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'] # type&run the above example/exercise in this cell def build_lyrics (word, r): ans = 0 for i in range(r): ans.append(word) return ans print(build_lyrics('I', 3)) ['I', 'I', 'I'l 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_3 = 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, , 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

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 Databases Questions!