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

Bruce McMinn
Bruce McMinn
10,030 Points

Works locally and in workspaces but not in interpreter for code challenge combiner

This works locally and in workspaces but not in the challenge. I have put it into the interpreter in a few different ways, like without the list etc. This is the only Treehouse code challenge I've found that was this open ended and didn't work. Kind of a bummer. Locally and in the workspace I get stringalert15.2 returned. Also, any idea why I have to use '' around inputs in Terminal?

list = ["string", 10, "alert", 5.2]

def combiner(list):

    word_list = []
    number_list = []

    for word in list:
        if isinstance(word, str):
            word_list.append(word)
            word_string = "".join(word_list)

    for number in list:
        if isinstance(number, (int, float)):
            number_list.append(number)

            number_sum = sum(number_list)
            number_str = str(number_sum)


    big_string = word_string + number_str

    print(big_string)

combiner(list)
Bruce McMinn
Bruce McMinn
10,030 Points

So I had to return the string not print it. And then not provide the list and not call it. Then it works!

Thanks for the To-Do list of things to do and not include. I also printed, called, etc.

1 Answer

Steven Parker
Steven Parker
229,695 Points

As you discovered, challenges often have specific requirements that may not be obvious when testing in an external REPL or a workspace.

For best results with challenges, always read instructions carefully, and do only what they ask for. Sometimes students do a few "extra" things and that can confuse the validation as well.