Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,031 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,031 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!")