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

Giel Jan Koek
Giel Jan Koek
377 Points

exception

Hi, I don't get why this code is not correct. It works fine in a different IDE. What am I doing wrong?

suggestinator.py
def suggest(product_idea):
    if len(product_idea) < 3:
        raise ValueError("A bit longer, please")
    return product_idea + "inator"

try:
    product_idea = input("What is the name of the idea? ")
    new_idea = suggest(product_idea)
except ValueError as err:
    print(err)
else:
    print(new_idea, "sounds like a good idea!")

3 Answers

Giel Jan Koek
Giel Jan Koek
377 Points

I finally got it. I was way overthinking it and learned some along the way.

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

Hey Giel Jan Koek, you code does indeed work!

It is the try statement below the function that is throwing off the checker. When parsing the code, the checker hits the unexpected input statement to which it does not have a response.

Remove the try statement, and you'll pass.

Post back if you need more help. Good luck!!

Giel Jan Koek
Giel Jan Koek
377 Points

Hi Chris, thank you for your response. I tried several things but it still doesn't run. Can explain it a bit more? Thanks.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

The issue is the try statement is not needed at all and should be eliminated entirely.

All this could should be removed to pass the challenge:

try:
    product_idea = input("What is the name of the idea? ")
    new_idea = suggest(product_idea)
except ValueError as err:
    print(err)
else:
    print(new_idea, "sounds like a good idea!")