Please help. Im stuck


#1

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


print join_strings(n)

#2

look:

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


print join_strings(n)
print join_string(["this", "should", "work"])

your function should also work for a list with 3 or more items, so using n[1] is not very wise.

don't use n in the function at all. you supply n as argument at function call which passed into the function parameter, so use the function parameter

don't use [1] because you don't know the length of the list

a function ends the moment a return keyword is reached, so your function ends in the first iteration of the loop, but what if the list contains 5 elements? Place return outside the loop so the whole loop can run


#3

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


print join_strings(n)

okay so ive got to here but what do I do with 'words'. surely I have to put something in the parameters next to it?


#4

no? words contains the list, then we loop over the list then we only need to add item to result


#5

thanks for the help. I am finding this section quite difficult though. I am also not understanding it that much. but thanks for the help anyways. :slight_smile:


#6

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