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

Swan The Human
seal-mask
.a{fill-rule:evenodd;}techdegree
Swan The Human
Full Stack JavaScript Techdegree Student 19,338 Points

I dont know how to read the preview well enough to see where my problem is.

I cant read the preview saying i have 2 errors well enough to know where i went wrong. I cant even understand where to start with this unless i look at my workspace from the video tutorial. thanks

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

except ValueError as err:
    print ('name too short'  )

Because the question is only asking you to raise an error, you do not need your entire last two lines of code. Raising the error will only create an error for an input value that you don't want which can then be handled later on the backend of the code.

Try again, but this time pay close attention to the question, it is asking for LESS THAN 3, which means if it is 3 long it should pass the error but if its 2 or less it should raise the exception. Also don't forget that you cannot use comparison operators between string and integer values as the computer reads them as two entirely different entities. Try converting the string into an integer that the computer can read and compare with.

PS: do try again before looking at my answer, if you still can't get it take a look.

1 Answer

 def suggest(product_idea):
    if len(product_idea) < 3:
        raise ValueError('Too Short')
    return product_idea + "inator"

# Comare operand on line two was wrong ('len(product_idea) <= 4' would have worked too)
# if statement must compare the length of the product idea with 3, so we include 'len()'