It works on IDLE


#1

I tried this, it works on IDLE though, but not able to move to the next topic:

n = ["Michael", "Lieberman"]

Add your function here

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

print join_strings(n)

Can someone suggest what is wrong here:

result = words[0] + str(n[i])


16 Using Strings in lists in functions
#2

I will give you a int on whats wrong. the scope of the list your function is using is wrong

I have inserted print statement in your code to help you debug it below:

n = ["Michael", "Lieberman"]

#Add your function here
def join_strings(words):
	result = ""
	for i in range(len(n)):
		
		#current word in loop
		print("Current word is " + n[i])
		
		result = words[0] + str(n[i])
		
		#current value of result
		print("result is now " + result +'\n')
		
	#final value of reult
	print ("result is finally "+ result)
	
	return result

join_strings(n)

names = "HumptyDumpty fell over the wall".split(" ")
#calling function on names
join_strings(names)

#3

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