Using strings in lists in functions - join_strings(['x', 'y', 'z', 'a']) returned 'MichaelLieberman' instead of 'xyza'


#1

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

Hello everyone! I need your precious help.

Apparently the output is the one that is intended in the exercise, however I get the following error:

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

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)

printscreen:


#2

Your function is referring to the global object, n when it should be referring to the local object, words.


#3

@mtf Thanks very much for your quick reply!

I have made this change but the error stills.


#4

There is still a reference to n that also needs to be changed to words.


#5

@mtf Thanks! It's fixed!


#6

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