Using strings in lists in functions, code seems right, but still gives error


#1



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

Traceback (most recent call last):
File "python", line 9, in
File "python", line 6, in join_strings
TypeError: unsupported operand type(s) for +: 'int' and 'str'


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

print join_strings(n)


It looks correct, but it's not for some reason


#2

Don't use range.
Using range, i is being set to an int instead of the string.
Replace this:
for i in range(len(words)):
With this:
for i in words:


#3

You will also need to have result first in the concatenation as otherwise it will put your words out of order.

result = result + i

instead of:

result = i + result


#4

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