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

Christopher byng
Christopher byng
375 Points

challenge task

I am having trouble with the next step to pass this challenge task.

suggestinator.py
def suggest(product_idea):
    text = len(product_idea) 
    if text < 3: 
        raise ValueError("you need more letters")
        return product_idea + "inator"

Ran 1 test in 0.000s

OK
F.
======================================================================
FAIL: test_exception_not_raised (__main__.TestRaiseExecution)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "", line 27, in test_exception_not_raised
AssertionError: None != 'baconinator' : I passed in 'bacon' and expected 'baconinator', but got 'None'

----------------------------------------------------------------------
Ran 2 tests in 0.000s

FAILED (failures=1)```

1 Answer

Jazz Atkin
Jazz Atkin
1,374 Points

You are currently passing the "return" statement inside of the "if" statement, as a result of the indentation. You want to pass the return statement AFTER the "if" statement, once you have ascertained that the text string is NOT less than 3. If you move the "return" statement back 4-spaces so that it is in line with the "if" statement, then your code will work!

def suggest(product_idea):
    text = len(product_idea) 
    if text < 3: 
        raise ValueError("you need more letters")
    return product_idea + "inator"

You also do not need to create "text" if you want to simplify. You could simply run "if len(product_idea) < 3" - I think!

def suggest(product_idea):
    if len(product_idea)  < 3: 
        raise ValueError("you need more letters")
    return product_idea + "inator"
Christopher byng
Christopher byng
375 Points

Wow I was overthinking this one. Thanks! Really helped alot.