16. Using Strings in Lists in Functions


#1



https://www.codecademy.com/courses/python-beginner-nzzVa/3/5?curriculum_id=4f89dab3d788890003000096


Output:
Michael
Lieberman
MichaelLieberman
None

Error message:
Oops try again. join_strings(['x', 'y', 'z', 'a']) returned 'xyza' instead of 'xyza'


It's adding my strings together without spaces, but i'm not sure how to include the space. Please can someone help?


n = ["Michael", "Lieberman"]

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

print join_strings(n)


#3

Don't print inside the function. Just concatenate and return the result.

Also, initialize result as an empty string.


#4

Ok, thank you - doesn't the line result = " " mean that i've initialised it? If it doesn't, then i'm not sure i understand how to initialise. thanks


#5

You did initialize it, but with a space character which is throwing off the result. Use the empty string, "" or ''.


#6

I see! Fixed now, thank you so much!


#7

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