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 trialbright chibuike
3,245 PointsRaising Exceptions
I have done this but still getting indentation error. def suggest(product_idea):
if len(product_idea) <= 3:
def suggest(product_idea):
if len(product_idea) <= 3:
raise ValueError("your product_idea is less than three")
return product_idea + "inator"
try:
product_idea =input("your product_idea? ")
result = suggest(product_idea)
except ValueError as err:
print("oh that's not a valid value.try again")
print("({})".fomat(err))
else:
print("your product{}".format(result))
2 Answers
Broderick Lemke
13,483 PointsHi bright!
It looks like things got a little complicated pretty fast in your answer. With treehouse quizzes it's a good bet not to do more than you're asked to. In this case they just asked you to raise an exception. you went and included a whole try-except block, asked for input, printed a bunch of stuff to the screen, and printed the results. While these would all be steps we'd need to follow in the real world, we should only follow the steps we're given as Treehouse breaks it down into easy manageable steps to build up to bigger applications. The other thing that I'd note is that Python is white-space dependent. Your first line starts to define a function, but then your if statement isn't indented properly. Make sure to watch your indentation.
Here's a copy of my code just to show you a working solution.
def suggest(product_idea):
if len(product_idea) < 3:
raise ValueError("This is too short")
return product_idea + "inator"
Quick note: I also want to point out that < and <= are different and in this case you were asked to check for values less than three, not less than or equal to. Good work though, and keep up the motivation and learning!
bright chibuike
3,245 Pointsthanks a lot Broderick Lemke. The code solved the task. I appreciate
Broderick Lemke
13,483 PointsAwesome, glad to hear it. Feel free to select my answer as the preferred answer so other students can see this problem as being solved! :)