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

not sure what I am missing.

suggestinator.py
def suggest(product_idea):
    return product_idea + "inator"

suggestion = "gg"
if len(suggestion) < 3:
    raise ValueError ("suggestion is less than 3 characters long")    
else:
    print(suggest(suggestion))

Ran 1 test in 0.000s

OK

EE

ERROR: test_exception_not_raised (main.TestRaiseExecution)

Traceback (most recent call last): File "", line 23, in test_exception_not_raised File "/workdir/utils/challenge.py", line 24, in execute_source exec(src) File "", line 6, in ValueError: suggestion is less than 3 characters long

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

ERROR: test_exception_raised (main.TestRaiseExecution)

Traceback (most recent call last): File "", line 30, in test_exception_raised File "/workdir/utils/challenge.py", line 24, in execute_source exec(src) File "", line 6, in ValueError: suggestion is less than 3 characters long


Ran 2 tests in 0.001s

FAILED (errors=2)

2 Answers

Howdy jeff! There is a much simpler way to do this if you look at what i have here.

def suggest(product_idea):
    if len(product_idea) < 3:
        raise ValueError("Must contain 3 or more characters.")
    else:
        return product_idea + "inator"

your issue here is that you are messing with your function. what you should be messing with is the variable inside of your Function you see? jeff matulevich

That helped

I did try it your way Christian Beckett and still failed, however not because of your code. I trimmed the

print(suggest(suggestion))

from mine and yours and it passed. there was not to be any output on this exercise . Your code was far cleaner than mine so your suggestion worked once I took my print off the end also.

again if you have any questions my friend feel free to ask. I'm also learning python so this is a learning experience for both of us. jeff matulevich Im happy to help any time :P