"Using strings in lists in fnuctions"


#1



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

When I click Save and Submit it just says:
Oops, try again. join_strings(['x', 'y', 'z', 'a']) returned 'MichaelLieberman' instead of 'xyza'

I have no Ideas what I did wrong please help me

MY CODE:

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

#2

here:

def join_strings(words):

you declare your function, and give it a parameter (words)

then when you call the function:

print join_strings(n)

you pass n as argument. the argument is copied into the parameter. So you should loop over the parameter inside the function, this way your function works for any list passed as argument when calling the function


#3

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