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

Challenge Task 1 of 1 I've made a function that creates brand new product names using artificial intelligence.

when i run this code on local python idle installed on my local computer it works but whe i try to preview it here ,it gives me traceback errors

suggestinator.py
def suggest(product_idea):
    if len(product_idea)<3:
       raise ValueError("product idea too short")
    return product_idea + "inator"

try:
    n = input("please suggest product idea")
    print(suggest(n))
except ValueError as err:
    print("please refuel")
    print(" {} ".format(err))  
else:
    print("we are good to go")

1 Answer

Brandon Oakes
seal-mask
.a{fill-rule:evenodd;}techdegree
Brandon Oakes
Python Web Development Techdegree Student 11,501 Points

First get rid of the second part of your function starting at the "try". You don't need that to pass the challenge

def suggest(product_idea):

if len(product_idea)<3:
    raise ValueError("product idea too short")
else:
    return product_idea + "inator"

So the code would actually pass the way you have it after you get rid of the code below try. I added an ELSE statement, but it will pass without one as well.