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

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.