Using strings in lists and functions


n = ["Michael", "Lieberman"]

Add your function here

def join_strings(words):
result = ""
for x in range(len(words)):
new = words[x]
return result

print join_strings(n)

My code is giving an error that I cannot comprehend..

Traceback (most recent call last):
File "python", line 10, in
File "python", line 7, in join_strings
AttributeError: 'str' object has no attribute 'append'

Please help!


You define a string result here:

result = ""

the append you use, is for list. (if you want result to be a list: result = [])
So, that is what the error messag says:

AttributeError: 'str' object has no attribute 'append'

str means strings, and is refering to your result variable.


Oops, i didn't check the exercise first, the whole point is to make a string.

in that case, this line:


you should change it to:
result = result + new
now you just add the letter to the string (yes, you can do this). And yes, you should be able to make this shorter, but i will leave that to you to figure out