Python Object-Oriented Python Inheritance Instances

corincraciun
corincraciun
2,235 Points

instances challenge oop python --> not expected output?

The code has the expected output in my interpreter, but i get error when i try to complete it in the challenge.

instances.py
def combiner(*args):
    strings = ""
    numbers = 0
    for item in list(args):
        if isinstance(item, str):
            strings += item
        if isinstance(item, (float, int)):
            numbers += item
    return strings + str(numbers)

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,823 Points

The parameter for the function is a single list. I added the following to your code:

def combiner(*args):
    strings = ""
    numbers = 0
    for item in list(args):
        if isinstance(item, list):
           print("i am a list")       
        if isinstance(item, str):
            strings += item
        if isinstance(item, (float, int)):
            numbers += item
    return strings + str(numbers)

print(combiner(["apple", 1]))
print(combiner(["apple", 5.2, "dog", 8]))

The result is:

i am a list                                                                   
0                                                                             
i am a list                                                                   
0  
corincraciun
corincraciun
2,235 Points

Now i noticed that i should have put a single argument, a list. so the correct code should have been. Thank you for the clarifications!

instances.py
def combiner(list):
    strings = ""
    numbers = 0
    for item in list:
        if isinstance(item, str):
            strings += item
        if isinstance(item, (float, int)):
            numbers += item
    return strings + str(numbers)