Python Python Basics Functions and Looping Raise an Exception

jeff matulevich
jeff matulevich
1,721 Points

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))
jeff matulevich
jeff matulevich
1,721 Points

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

Christian Beckett
Christian Beckett
11,118 Points

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

jeff matulevich
jeff matulevich
1,721 Points

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.

Christian Beckett
Christian Beckett
11,118 Points

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