Question: The following code has a bug in it . Identify which line has the bug, what the issue is . This code should take in

The following code has a bug in it. Identify which line has the bug, what the issue is.
This code should take in a list of strs, and return a string that is all the words separated by '.'
so given ['This','is','an', 'example'] it should return 'This. is. an. example. '
1| def add_emphasis(list_of_words):
2| new_sentence =""
3| for w in list_of_words:
4| new_sentence = w +"."
5| return new_sentence
6| phrase =['This','is','an', 'example']
7| print(add_emphasis(phrase))
(If you are tring this in vscode make sure you delete the line numbers I've added)
Choice 1 of 5: There is no error
Choice 2 of 5: Line 3, syntax error, the for loops needs to be written differently
Choice 3 of 5: Line 4, logic error, overwriting value in variable
Choice 4 of 5: Line 4, runtime error, can't add list of strings to a string
Choice 5 of 5: Line 7, runtime error, the function isn't being called right

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!