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 trialNick Evershed
570 PointsStuck
I've made a function that creates brand new product names using artificial intelligence.
I have a problem though, people keep on adding product ideas that are too short. It makes the suggestions look bad.
Can you please raise a ValueError if the product_idea is less than 3 characters long? Thanks in advance!
I'm pretty confused at this point, and python is overwhelming me, I really want to complete this course
def suggest(product_idea):
return product_idea + "inator"
if product_idea < 3:
raise ValueError("Oof")
2 Answers
Jeff Muday
Treehouse Moderator 28,720 PointsSee how close you were! :-) This will work.
def suggest(product_idea):
if len(product_idea) < 3:
raise ValueError("Oof")
return product_idea + "inator"
Jeff Muday
Treehouse Moderator 28,720 PointsA few things to work on:
1) to test the length of a string, you should use the len() function.
if len(product_idea) < 3:
raise ValueError("some error message that would make sense")
2) Make sure to always indent to ensure your statement is inside the desired program block. In this case the "if" clause is not inside the function block
3) Program flow. You need to check the length of the product idea and raise the error FIRST, rather than just return the concatenated string.
If you make those changes, you can pass the challenge.
Good luck and enjoy your courses.
Nick Evershed
570 PointsUgh I tried this and its still not working :(
Leon Silcott
27,584 PointsLeon Silcott
27,584 PointsHey,
I'm not sure if this helps. But I would have done something like.