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 trialGiel Jan Koek
377 Pointsexception
Hi, I don't get why this code is not correct. It works fine in a different IDE. What am I doing wrong?
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
377 PointsI finally got it. I was way overthinking it and learned some along the way.
Chris Freeman
Treehouse Moderator 68,457 PointsHey 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
377 PointsHi 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
Treehouse Moderator 68,457 PointsThe 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!")
Samuel Jiménez
Python Development Techdegree Student 396 PointsThe problem is the indentation of the try/except/else statement. They all go inside the function.
Chris Freeman
Treehouse Moderator 68,457 PointsThe try
statement shouldn’t be there at all.