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 trialBrent Capuano
949 PointsHelp! Raising an exception challenge quiz.
In the lesson, we created an exception with a numerical value. In the quiz, they want us to raise an exception for the number of letters in a word. How do you write the equivalency equation (ie < > +) for a word with less than three characters? I am using Python.
def suggest(product_idea):
if product_idea < 3:
raise ValueError("Sorry, your title is too short.")
return product_idea + "inator"
product_idea = input("Give me a word")
1 Answer
Steven Parker
231,275 PointsYour operator is correct, but instead of comparing the string itself with 3, you'll want to compare the length of the string.
Also, you only need to define the function, you won't need to call it yourself or "input" anything.
Brent Capuano
949 PointsBrent Capuano
949 Pointswhat is the command for length of string?
Steven Parker
231,275 PointsSteven Parker
231,275 PointsThe "len" function gives you the length of something:
if len(product_idea) < 3: