Using strings in lists and functions


#1

n = ["Michael", "Lieberman"]

Add your function here

def join_strings(words):
result = ""
for x in range(len(words)):
new = words[x]
result.append(new)
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!


#2

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.


#3

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

in that case, this line:

result.append(new)

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