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 trialThe Gull
1,919 PointsQuestion on "Raise an Exception" Objective 1 [Solved]
Am I misusing len() to represent the number of characters in the product_idea ??
def suggest(product_idea):
return product_idea + "inator"
if len() <= 3:
raise ValueError (product_idea + "must be longer than characters")
The Gull
1,919 Pointsnah i figured it out yesterday but thank you for responding. Btw, I like your avatar and your name lol
Anesu Antonatte Chibanda
2,238 Pointshow did you figure it out?
boi
14,242 PointsAnesu Antonatte Chibanda Past your code, let me have a look.
Anesu Antonatte Chibanda
2,238 Pointsboi cant seem to convert my code so here is the copy and past
def suggest(product_idea): return product_idea + "inator" if product_idea <=3: raise ValueError(product_idea +"characters must be longer than that")
Anesu Antonatte Chibanda
2,238 Pointsboi Thank you so much i managed to execute it!!
1 Answer
boi
14,242 Pointsdef suggest(product_idea):
return product_idea + "inator"
if product_idea <=3:
raise ValueError(product_idea +"characters must be longer than that")
To learn how to paste your code go here
Now let's analyze your code. You have 3 errors and 1 unnecessary line.
def suggest(product_idea):
return product_idea + "inator" 👈# Error 1
if product_idea <=3: 👈# Error 2 and Error 3
raise ValueError(product_idea +"characters must be longer than that") 👈# Extra code
Error 1
The return
statement returns the value from a function and ends the function. So return
should always be called at the end of a function.
Error 2
The product_idea
argument is expecting a string object NOT an integer object. So basically you're telling the code to compare a string object to an int object 👉 if string <= 3
which is a wrong statement. Instead, you should be telling the code to compare the length of the string object to an integer object. In the case of getting a length of an object, it would give you back an integer. Which is what you should do.
Error 3
You stated <= 3
which means less OR equal to three, but the challenge wants you to make sure it is LESS than three, so even if the length is equal to three that's acceptable.
Extra code
You only need to raise ValueError
, but although it works as it is.
If you need more help, let me know.
boi
14,242 Pointsboi
14,242 PointsYes, you're. Need help with the solution?