Python Object-Oriented Python Inheritance Instances

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?

instances.py
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])  

3 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 50,933 Points

The challenge wants you to return the string. You are printing.

doh!, thanks

James Ball
James Ball
1,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).