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 trialRyan Stjernholm
452 PointsHow do i label < 3 characters?
Is everything right up to where i get the error for my int(3)? How do i make the label for "3 characters"?
def suggest(product_idea):
return product_idea + "inator"
if product_idea < int(3)
raise ValueError
1 Answer
Cooper Runstein
11,850 PointsYou have a few problems with your code: First, your syntax is never going to work in your if statement because you're missing the ":" at the end of the line. Second, your if statement right now isn't doing anything meaningful, how would a computer know if the value of a string is less than 3? You need to find the length of the string product_idea using the len method. Also, there's no reason to use the int function on 3, 3 is already an integer and there is no possible way in your code for it to be anything else.
if len(product_idea) < 3:
raise ValueError
Finally, even if you fix your if statement, it won't do anything. Why? Because it's following a return statement that will always return, meaning the rest of the code after the return won't run. To fix that, you need to put your if condition before the return, that way if you insert a string that's less than 3 characters in length, it'll get "caught" by the exception and won't be returned.
Ryan Stjernholm
452 PointsRyan Stjernholm
452 PointsYou just cleared up so much confusion, I seriously can't thank you enough!