16 Using strings in lists in functions


#1

Hi!
I've tried the code that seems to be on all the threads but it's not working for me. It says the list ['x','y','z','a'] is returning z instead of xyza.
Here is my code:

n = ["Michael", "Lieberman"]

Add your function here

def join_strings(words):
result=""
if i in range(len(words)):
result += words[i]
return result

print join_strings(n)

if you can help it is much appreciated!


#2

Ok, so I got past that lesson because I copy and pasted one of the codes from the thread which was:

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

print join_strings(n)

Can someone point out to me the difference between what I had typed above and the copy and pasted code?


#3

There is the difference. In the first case, i is undefined and will throw a reference error. In the second, i is correctly defined in the for statement.


#8

Hello,

I'm stuch on this as well. Here is my code: can you tell me what is wrong, please?

n = ["Michael", "Lieberman"]

Add your function here

def join_string(words):
result = " "
for i in range(len(words)):
result += words[i]
return result

print join_strings(n)


#9

The result string should be initialized as the empty string, with no white space.

result = ""

#11

it worked this way for me: