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

Deonte Meriwether
Deonte Meriwether
1,513 Points

value error format

Im having trouble raising value errors and creating the condition when I need to calculate the number of characters inpu

suggestinator.py
def suggest(product_idea):
   if len(product_idea) < 3 raise ValueError("Too short try again")

    return product_idea + "inator"

2 Answers

Daniel Turato
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Daniel Turato
Java Web Development Techdegree Graduate 30,124 Points

Raising the error should be on it's own separate line like so:

def suggest(product_idea):
   if len(product_idea) < 3:
       raise ValueError("Too short try again")

    return product_idea + "inator"
Deonte Meriwether
Deonte Meriwether
1,513 Points

Oh I see now. Thank you for helping me with this one Daniel! It seems like I was so close but still so far from solving this one :)

Zach Newman
Zach Newman
1,138 Points

I'm having trouble on this one as well with the formatting and applying what I need following the example set by daniel, when I run it I get this:

ERROR: test_exception_not_raised (main.TestRaiseExecution)

Traceback (most recent call last): File "", line 24, in test_exception_not_raised File "", line 3, in suggest ValueError: Too Short, try again.

======================================================================

FAIL: test_exception_raised (main.TestRaiseExecution)

Traceback (most recent call last): File "", line 32, in test_exception_raised AssertionError: ValueError not raised : I passed in 'a' and expected a ValueError to be raised


Ran 2 tests in 0.000s

FAILED (failures=1, errors=1)

I'm not quite where I'm going wrong