Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Grant Murphy
Grant Murphy
10,072 Points

My code outputs the expected output in the work-space but receiving "Did not get expected output". Help!

Title says it all, my function works as asked but not passing the test. So I do not know if I am simply not reading the question right or maybe I am not returning the information the correct way. Again I am not sure. Any help would be greatly appreciated, thank you!

instances.py
def combiner(*args):
    num = []
    words = []
    final = ""
    for item in args:
        if isinstance(item, (int, float)):
            num.append()
        else:
            words.append(item)
    lsum = sum(num)        
    words.append(lsum)
    listToStr = "".join([str(elem) for elem in words]) 
    return listToStr

1 Answer

You have two issues

1) You are missing an argument so you aren't appending anything here:

num.append()

2) In using *args you are accepting a variable number of arguments. The challenge specifies that the function will take a single list as an argument. Hint: Don't use *args.

Try this in a workspace to test

def combiner(*args):
    num = []
    words = []
    final = ""
    for item in args:
        print(item)

        if isinstance(item, (int, float)):
            num.append(item)
        else:
            words.append(item)
    lsum = sum(num)        
    words.append(lsum)
    listToStr = "".join([str(elem) for elem in words]) 
    return listToStr



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