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 trialRichard Yates
Courses Plus Student 557 PointsPython Basics Raise an Exception Challenge Task #1
I can't seem to see what I'm doing wrong, thanks!
def suggest(product_idea): return product_idea + "inator" if product_idea =< 3 characters: raise ValueError("Please use three characters minimum")
3 Answers
KRIS NIKOLAISEN
54,972 PointsSome hints:
- The code exits with the return statement so anything you add should come before this.
- You will want to compare the length of product_idea to 3.
- The comparison operator for less than or equal to is <=
Brandon DeSouza
3,126 Points2 hints. I'm going to build off what Kris said:
You will want to COMPARE the LENGTH of product_idea to 3. (How do you compare values) The comparison operator for less than or equal to is <= (The requirement is for LESS than 3)
fill in the blanks:
def suggest(product_idea): ?????? = ???(???????_????) if ?????? <= ?: raise ValueError("Please enter product name greater or equal to thee characters.") ????: return product_idea + "inator"
BRYAN ASHER
Python Development Techdegree Student 1,653 PointsYour hint was VERY helpful Brandon!!! I read this question so many times and I just couldn't wrap my brain around where to start. THANK YOU :)
Tom Galkov
4,870 PointsI did everything and it still giving me two error this is my code
def suggest(product_idea): length = int(product_idea) if length <= 3: raise ValueError("Please enter product name greater or equal to thee characters") length: return product_idea + "inator"
please help
Thank you
BRYAN ASHER
Python Development Techdegree Student 1,653 PointsThis was my code to solve this (It's similar to yours):
def suggest(product_idea): result = len(product_idea) if result < 3: raise ValueError("Enter a word longer than three letters") return product_idea + "inator"
So, like Brandon's hint with the question marks, you're taking the result and using the len function to compare the length of the string to see if it's three letters or less. If it's not, you raise the ValueError. (Also the code above gets bunched up because it's a comment, rather than spaced out correctly)
Richard Yates
Courses Plus Student 557 PointsRichard Yates
Courses Plus Student 557 PointsThank you for the response. I changed it to what you'll see below and it still says I have two errors. I also added my code AFTER just to see and it still shows errors. Thank you.
if length of product_idea <= 3: raise ValueError("Please enter product name greater or equal to thee characters.") def suggest(product_idea): return product_idea + "inator"