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

Jesse Nieman
Jesse Nieman
4,452 Points

I am getting stuck on this raise an exception question:

Here is my code. Am I heading in the right direction? Totally off?

Thanks for the insight!

suggestinator.py
def suggest(product_idea):
    product_idea = input("give me an idea  ")
    return product_idea + "inator"
    if product_idea !> len(3):
        raise ValueError("You need a bigger idea.")

1 Answer

rydavim
rydavim
18,814 Points

You've got the right idea, there are just a couple of small problems. The order of your code is a little bit off, and your length comparison has a syntax problem.

def suggest(product_idea):
    product_idea = input("give me an idea  ") # You don't need to get this, it's provided to the function.
    return product_idea + "inator" # Your code should go before the return statement.
    if product_idea !> len(3): # You want to compare the length of the product idea to the num 3. Ex: len(str) < num
        raise ValueError("You need a bigger idea.")

That should help you work out the last bit, but let me know if you get stuck and we can work through a solution. Nice job, keep it up!

Jesse Nieman
Jesse Nieman
4,452 Points

This helped a ton. I was able to complete the exercise.