16. Using strings in lists in functions


#1



Oops, try again. Your code looks a bit off. Check the console window for errors!

i guess there is something wrong with the append statement which i cant figure out.


Replace this line with your code. 
n = ["Michael", "Lieberman"]
# Add your function here
def join_strings(words):
    result=""
    for i in range(len(words)):
        result.append(words[i])
    return result


print join_strings(n)


#3

You were so close!

All you need to do for your code to work is remove words and the brackets from this line,

should be just,

result.append(i)


#4

it still throws an error :frowning:


#5

Okay got it! You just have to use += instead of .append(),

result += words[i]

should work just fine. :slight_smile:


#6

hey thanks, it worked :slight_smile:
the append function is anyways used to add anything at the last of the list. so it wasnot of any use here right?


#7

2 posts were split to a new topic: 16. Using strings in lists in functions


#8

That worked thanks! I am not sure why my comment has to be at least 20 characters but you are correct the return has to be on the same indent as the "for" statement.


#9

That worked but is there a way to write it using "append"?


#10

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.