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
Lesedi Ncube
441 PointsI am failing to complete the 'Raise an exception' code challenge quiz on Python, please help.
How do l raise a ValueError if the user input is less than 3 characters long in a case and product_idea is a string ?
def suggest(product_idea): return product_idea + "inator"
2 Answers
Jasper Maposa
26,919 PointsJust to illuminate Thomas' answer
def suggest(product_idea):
if len(product_idea) < 3:
raise ValueError('Too shot')
return product_idea + 'inator'
Steven Parker
243,657 Points Treehouse discourages explicit answers without explanations, and they have redacted them on occasion.
Steven Parker
243,657 PointsThough not formatted to display lines and indentation, the solution provided by Thomas is essentially correct. You just need to add a conditional "if" line which then controls a "raise" statement.
Thomas Beaudry
29,084 PointsThomas Beaudry
29,084 Pointsdef suggest(product_idea): if len(product_idea) < 3: raise ValueError return product_idea + "inator"