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 trial

Python Python Basics Functions and Looping Raise an Exception

Richard Yates
PLUS
Richard Yates
Courses Plus Student 557 Points

Python 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

Some 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 <=
Richard Yates
Richard Yates
Courses Plus Student 557 Points

Thank 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"

Brandon DeSouza
Brandon DeSouza
3,126 Points

2 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
seal-mask
.a{fill-rule:evenodd;}techdegree
BRYAN ASHER
Python Development Techdegree Student 1,653 Points

Your 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
Tom Galkov
4,870 Points

I 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
seal-mask
.a{fill-rule:evenodd;}techdegree
BRYAN ASHER
Python Development Techdegree Student 1,653 Points

This 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)