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

Scott Bump
PLUS
Scott Bump
Courses Plus Student 384 Points

I'm getting an error during my raise exception task. I can get my code to work in the workspace. What gives?

It is only in the suggestinator.py does it error. It says the error is on line 8.

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 20, in execute_source exec(src) File "", line 8, in

EOFError: EOF when reading a line

suggestinator.py
def suggest(product_idea):
    number_of_characters = len(product_idea)
    if number_of_characters < 3:
        raise ValueError("The product idea is less than 3 characters. Please create one that is 3 characters or more. Thank you!")
    return product_idea + "inator"

try:
    product_idea = str(input("Please enter your idea!"))
    final_name = suggest(product_idea)

except ValueError as err:
    print("{}".format(err))

else:
    print("Your idea name is {}".format(final_name))

2 Answers

Steven Parker
Steven Parker
231,275 Points

You're working way to hard! For the challenge you only need to update the function.

You don't need to call it, catch the exception, or print anything.

Scott Bump
Scott Bump
Courses Plus Student 384 Points

Hi Steven,

Thanks for that! I was so caught up in trying to understand calling the exception I didn't realize I was doing too much. Much appreciated!

Allan Storgaard
Allan Storgaard
1,037 Points

def suggest(product_idea): if int(len(product_idea)) < 3: raise ValueError("Please add more letters") return product_idea + "inator"