this code works in workspaces. Why doesn't it work for the challenge?
Hi, This code works in workspaces. Why doesn't it work for the challenge?
def combiner(items): # Hold values strings = "" nums = 0 # Loop through list for item in items: # Test type of each element # If string, concatenate each to itself if isinstance(item, str): strings += item # else if float or int, add together elif isinstance(item, (float, int)): nums += item print(strings + str(nums)) combiner(["apple", 5.2, "dog", 8])
KRIS NIKOLAISENPro Student 50,933 Points
The challenge wants you to return the string. You are printing.
James Ball1,995 Points
I was making the same mistake in a different challenge. Print and return are actually different statements (although they may sometimes have the same behavior). Print only displays an output to the user whereas return gives back a result to the function call. All functions return a value, even if there is no return statement (in which case the function will return None).