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

Can someone please explain this error? ERROR: test_exception_not_raised (__main__.TestRaiseExecution)

suggestinator.py
def suggest(product_idea):
    if product_idea != 4:
        raise ValueError("Product names need to have 4 or more characters")
        return product_idea + "inator"    

print("Product name too short! Try again...")

1 Answer

Steven Parker
Steven Parker
231,275 Points

You're getting close, here's some hints:

  • you need to check the length of the idea string, not the string itself
  • the exception should only be raised if the length is less than 3
  • the "return" should not be controlled by the "if"
  • all the code should be done inside the function
  • you don't need to "print" anything

Thank you very much:)

I cannot do it, I understand what I need to do but I don't know how...

Steven Parker
Steven Parker
231,275 Points

OK, a more explicit version of the same hints:

  • change "product_idea" to "len(product_idea)" in the "if" statement
  • change the test from " != 4" to " < 3"
  • reduce the indentation of the "return" statement (back to what it was originally)
  • don't write any code after the function,
  • in particular, get rid of the "print" statement