Using strings in lists in functions


#1



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


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


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


print join_strings(n)


#2

Youre not taking advantage of for loop.
also its important to note that your function should able to deal any lists not just n.

an example will make things clear..

suppose there is list of numbers..

x = [1,2,3,4]

and I want to find sum of all numbers, How do I use for loop to do this?

sum = 0
for i in x:
    sum = sum + i

print sum # This will print 10

same way you can make some changes here..

result = words[0] + words[1]


#3

Okay I understand it now. Thank you.


#4

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