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 trialAbdul haseeb
569 Pointshelp, please !
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? product_idea is a string. Thanks in advance!
def suggest(product_idea):
if product_idea<3:
raise valueError("product ideas are too short")
return product_idea + "inator"
1 Answer
Eric M
11,546 PointsHi Abdul,
There's a couple of different things to change.
Firstly, Python is case sensitive so valueError
and ValueError
are not the same. You want ValueError
.
Secondly, Python uses whitespace to determine the structure of your code, as it stands return
is not indented consistently with the rest of your program, maybe copy the whitespace in front of your if
statement and replace the whitespace in front of return
to be sure it's exact.
Okay, so those are syntax errors, no big deal but they can make the real problem harder to spot. The main issue here is that you're comparing a string product_idea
with an int 3
and asking python which is greater. Is a word greater than a number? Python has no idea how to figure that out. Is the number of characters in a word greater than a number? That we can work with.
Python has a way to get the number of characters, or length, of a string. If you use this instead of the string itself, you'll be able to pass this challenge.