16 Using strings in lists in functions


#1

Hi all,

I'm running into problems with:

n = ["Michael", "Lieberman"]

def join_strings(words):
    result = ""
    for i in words:
        result = i + n[1]
        return result

print join_strings(n)

It returned a result, but gives me somer error in the console.

I looked at all the other answers here, and none of their solutions got the right solution.

Thanks in advance!


#3

the function should also work if words is a list with 3 or more words:

n = ["Michael", "Lieberman"]

def join_strings(words):
    result = ""
    for i in words:
        result = i + n[1]
        return result

print join_strings(n)
#  function should also work for this function call
print join_strings(["this","should", "work"])

How this will help you further, if you need more help, post an updated version of your code


#4

return result should align to for, and in the formula for result you have to change result = result + i. If you add n[1], what will happen if your start list don't have the name n?


#8

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