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

Cedrick Cyizere
Cedrick Cyizere
275 Points

I am getting an exception not raised error and an EOF error i don't know what seems to be the problem .

suggestinator.py
def suggest(product_idea):
    if len(product_idea) <= 3:
            raise ValueError("the value is less than 3 characters")
    return product_idea + "inator"
try: 
     suggest( product_idea=(input("please choose a product ")))
except ValueError as err:
    print("the value is less than 3 characters")
else : 
     print (product_idea)

2 Answers

Joseph Yhu
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Yhu
PHP Development Techdegree Graduate 47,171 Points

You don't need any of that extra stuff; all you need is this part:

if len(product_idea) <= 3:
    raise ValueError("the value is less than 3 characters")

Actually, the extra stuff might be why you are getting errors.

Luke Davis
Luke Davis
1,394 Points

I've seen the answer now just want to know why this doesn't work i can run it and it does what the task asks and runs fine just keep getting 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: the product has to be longer than 3 characters

Any chance you can elaborate

def suggest(product_idea): return product_idea + "inator" product_idea = "a"

if len(product_idea) < 3: raise ValueError("the product has to be longer than 3 characters")

else: print(product_idea)

Joseph Yhu
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Yhu
PHP Development Techdegree Graduate 47,171 Points

Again, you don't need the else clause; you only need:

if len(product_idea) < 3:
    raise ValueError("the product has to be longer than 3 characters")

And you should put it before the return.