Python Object-Oriented Python Inheritance Instances

Please explain why I'm getting an error (Bummer) when submitting code. The function is returning string as expected.

The combiner function is returning string as expected.

instances.py
combo = ["apple", 5.2, 8, "dog"]
numberlist = []
stringlist = []
def combiner(item):

    for x in combo:
        if isinstance(x, str):
            stringlist.append(x)
        else:
            numberlist.append(x)

    num1 = sum(numberlist)
    str2 = "".join(stringlist)

    str3 = str2 + str(num1)
    return str3

result = combiner(combo)
print(result)

2 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,836 Points

Your parameter is item so you should iterate with that.

for x in item:

Currently your function only returns the results for list combo so if the checker were to submit for example

result = combiner(["test", 1, 2, 3])

the result would still be appledog13.2

Thank you Kris for your feedback. It worked.

combo = ["apple", 5.2, 8, "dog"]

def combiner(item): numberlist = [] stringlist = [] for x in item: if isinstance(x, str): stringlist.append(x) else: numberlist.append(x)

return "".join(stringlist) + str(sum(numberlist))

combiner(combo)