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

Angel Miranda
Angel Miranda
2,433 Points

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
216,810 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
Angel Miranda
Angel Miranda
2,433 Points

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
216,810 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