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 Python Basics Functions and Looping Raise an Exception

Khaleel Yusuf
Khaleel Yusuf
15,208 Points

suggestinator.py

I keep on getting an AssertionError. What's wrong with my code?

suggestinator.py
def suggest(product_idea):
    return product_idea + "inator"
    if len(product_idea) < 3:
        raise ValueError("must be more than 3 characters long!")
Steven Parker
Steven Parker
231,248 Points

Please post questions only once. This is a duplicate of your other question.
You might want to delete that one, click the little rectangle with the 3 dots to see that option.

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

Steven is correct, it is best if you only ask the question once.

To address your question about the assertion error:

*You have the right code, but the wrong order. *

If you reverse the order of the two conceptual tasks, check the length of the string first, and then raise a ValueError. And finally, return your product idea.

A simple rearrangment of the lines gives you the correct answer--

def suggest(product_idea):

   # check idea string first!
    if len(product_idea) < 3:
        raise ValueError("must be more than 3 characters long!")  # return an error

    # finally, return the product idea suggestion
    return product_idea + "inator"