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

Challenge Task: Object-Oriented Python...Not sure what I'm doing wrong

Hey folks! I'm working to understand why I'm getting errors with this challenge. The script below works fine in my environment and is using the isinstance command to verify each item provided in the list and then combines the item based on type (str, int, float). Any ideas on what the challenge is looking for that I'm missing?

instances.py
def combiner(list):
    text = ""
    numbers = 0
    for i in list:
        if isinstance(i,str):
            text += i
        elif isinstance(i,(int,float)):
            numbers += i
        else:
            print("unexpected type, please provide int, str, or float.")
            break
    output = str(text) + str(numbers)
    print(type(output))
    print(output)

2 Answers

Usually it is best to only to do what the challenge asks. Sometimes things like extra print statements can cause a challenge to fail. However in your case the challenge fails because you are asked to return the string which you haven't done.

Thanks for that! I was just reviewing other answers and was missing that it said return... I just updated my code to return output instead of print. Thanks!