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 trialKanyon Dodson
453 Pointswhats wrong with my code
can someone help explain what im doing wrong
def suggest(product_idea):
return product_idea + "inator"
if product_idea <= 3:
raise ValueError("make your product idea more than 3 charactors")
2 Answers
Steven Parker
231,269 PointsYou're close, but I see 3 issues:
- the new code must be done before the return
- it must also be indented to be part of the function
- the character requirement in the instructions is at least 3, not more than 3.
Asher Orr
Python Development Techdegree Graduate 9,409 PointsHi Kanyon- remember that the challenge is asking you to raise a ValueError if the string "product_length" is less than 3 characters.
In your code, you're first returning whatever is passed in as the product idea with "inator" added to it.
def suggest(product_idea):
return product_idea + "inator"
#in your code, you are first returning whatever is passed in as the argument (product_idea)..
#... then adding "inator" to that string.
When you click "Check Work", the Treehouse checker will run code like this:
suggest("repair")
Since the checker passed in "repair" as the argument, the code will return something like this:
repairinator
Before this happens, you want to raise a ValueError if the product_idea is less than 3 characters long. Your code should start with raising the ValueError IF the product_idea is less than 3 characters.
Let's get back to your code.
def suggest(product_idea):
if product_idea <= 3:
#you want to properly indent this, so Python knows it's part of the suggest function
#also, remember that product_idea is a string. Go back through your notes, and check what Craig said to do when you need to find the length of a string.
#lastly, notice that "<=" means "less than or equal to." It's supposed to be "less than" only.
raise ValueError("make your product idea more than 3 charactors")
Your code should start like this:
def suggest(product_idea):
#put your if statement here:
#then raise the ValueError
Once you've done that, add an "else" statement at the end. Like this:
def suggest(product_idea):
#put your if statement here:
#then raise the ValueError
#else:
#return the product_idea + "inator"
Does this answer your question? You have the right idea, you just need to re-arrange some of your code and make sure it's indented properly.