'for loop with range' doesn't work...[Michael Lieberman]


Hi, I’m just newbie in coding stuff.
Here my code is as below.

n = [“Michael”, “Lieberman”]
def join_strings(words):
[tab]result = “”
[tab]for i in range(0, len(words)):
[tab][tab]result = result + words[i]
[tab][tab]return result

print join_strings(n)

it results out just Michael…
can anybody help me plz???

thank you


by default a function returns None at the end. If we want to return something else at the end of the function, we can use the return keyword. But returning is the last thing a function does, the function ends when the return keyword is reached

so your function ends in the first iteration of your loop, but to get the correct string, the loop needs to make all its iterations. How do we fix this?


Thx for your reply. I think I should remove indentation[tab] before ‘return’ keyword. Thanks a lot!!


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