Using strings in lists in functions what am I doing wrong?


#1

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

Traceback (most recent call last):
File “python”, line 8, in
File “python”, line 6, in join_strings
TypeError: cannot concatenate ‘str’ and ‘int’ objects



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



#2

using range() will produce a list of integers which you can use as indexes to get values from words list, which you can then add to result. Or just get rid of range so you get the values/items from the list directly


#3

result = result + words[i]

got it, thanks :slight_smile:


#4