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

its telling me that ValueError isn't raised

suggestinator.py
product_idea = 3


def suggest(product_idea):
    if product_idea != 3:
         raise ValueError("add more letters")
    return product_idea + "inator"
print(format(suggest))

1 Answer

Steven Parker
Steven Parker
229,732 Points

The instruction say to "raise a ValueError if the product_idea is less than 3 characters long". There's a few issues here:

  • the length of the string should be tested, not the string itself
  • the test should check for less than 3 instead of not equal to 3
  • you don't need to add any code outside the function
  • you don't need to print anything

I changed product_idea = 3 to product_idea = Len("abc"), != to < , and deleted everything after return but now its throwing this error: File "", line 4, in suggest TypeError: '<' not supported between instances of 'str' and 'int'

Steven Parker
Steven Parker
229,732 Points

A couple more hints:

  • you should not be creating a variable (or adding any other code) outside of the function
  • the "len" function can be used inside the function in the comparison, but it must be spelled in lower case