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 trialTaylor Han
3,701 PointsIssues raising ValueError
Hello,
I'm stuck on how to raise the ValueError. I think the syntax is ok, but challenge says its missing something.
if len("product_idea") <= 3:
raise ValueError ("At least three characters please")
def suggest(product_idea):
return product_idea + "inator"
2 Answers
joelearner
54,915 PointsHi Taylor,
It appears that your ValueError statement is outside of the function. Try placing your if/ValueError inside the function, above the return.
Also, you wrote: if len("product_idea") <= 3:. This will make product_idea a string. Try dropping the quotes so it will be read accurately by the computer.
With those 2 small changes, your code should look something like this:
def suggest(product_idea):
if len(product_idea) <= 3:
raise ValueError ("At least three characters please")
return product_idea + "inator"
Cheers!
Oli Flemmer
13,394 PointsYou've got the right idea with almost perfect code but you have to put your if statement inside the function. IF the product idea isn't long enough then raise an error ELSE it should return " product_idea + "inator" "
Taylor Han
3,701 PointsThank you!
Taylor Han
3,701 PointsTaylor Han
3,701 PointsAh thank you for showing me the code too! It was driving me nuts haha. I got it now, thanks!