16/18 Using strings in Lists and Functions



I might just be overlooking the obvious here, but what am I doing wrong?

n = ["Michael", "Lieberman"]
# Add your function here
def join_strings(words):
    result = ""
    for words in n:
        result = result + words
    return result

print join_strings(n)

error returns:

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

What am I doing wrong?
Why is it referring to xyza whilest this is mentioned nowhere in the exercise?


for words in n:

Should be

for word in words: #as n is your example input but not your actual function parameter

Xyza is one of codecademy's test cases too see if your code passes :slight_smile:


the exercise is going to call your function with different arguments to see if it is working.

so the exercise will execute a function call:

join_strings(['x', 'y', 'z', 'a'])

so now inside your function words (the function parameter) will hold the following list:

['x', 'y', 'z', 'a']

so i would loop over the function parameter, this way, your function works for more then just one list


Thanks guys! XYZA got me all confused but it makes sense now.