Can't make the def. work in 16/18


#1

n = ["Michael", "Lieberman"]
-comment- Add your function here

def join_strings(words):
[tab] result = ""
[tab]for i in range(len(n)):
[tab][tab]result += words[i]
[tab]return result

print join_strings(n)

I'm using the code above (with the proper spacing, i'm using [tab] to represent the spaces), but whenever i run it it gives me the error "Oops, try again. join_strings(['x', 'y', 'z', 'a']) returned 'xy' instead of 'xyza'".

What i am doing wrong?


#2

the way i fixed it was instead of using
range(len(n))

just make it 'words' so like so

def join_strings(words):
    result = ""
    for i in words:
        result += words[i]
    return result
print join_strings(n)

Thats not all you need to do to fix it. you also need to change the function inside the for loop to make it

result += i


#3

n = ["Michael", "Lieberman"]
def join_strings(words):
result = ""
for i in words:
result += i
return result
print join_strings(n)

That did it for me. Thanks. result += i

Why doesn't result += words[i] ???