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

Sanamdeep Singh
seal-mask
.a{fill-rule:evenodd;}techdegree
Sanamdeep Singh
Python Web Development Techdegree Student 1,741 Points

Can't figure out this question, can someone help ?

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? Thanks in advance!

suggestinator.py
def suggest(product_idea):
    if product_idea <= 3:
        raise ValueError("Need a longer idea.")
    return product_idea + "inator"

10 Answers

Sanamdeep Singh
seal-mask
.a{fill-rule:evenodd;}techdegree
Sanamdeep Singh
Python Web Development Techdegree Student 1,741 Points

Thanks guys, I got this and it worked.

def suggest(product_idea):
    if len(product_idea) < 3:
        raise ValueError("Please try again.")
    return product_idea + "inator"
Chad Sutton
Chad Sutton
2,483 Points

recall the len() concept to return how many characters in a string. Almost there!

such a simple explanation so helpful thanx

Craig Dennis
Craig Dennis
Treehouse Teacher

Yeah, what does your current code look like Sanamdeep?

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

product_idea is a string. How do you determine the number of characters in a string?

Let me know if that hint doesn't do it for you ;)

Antonio De Rose
Antonio De Rose
20,885 Points

Sanamdeep Singh did you get it right, if not could you send the code, you have tried so far

I struggled with this one for a bit but I finally figured it out....

def suggest(product_idea):
    if len(product_idea) <= 3: 
        raise ValueError("You need a longer idea!")
    return product_idea +"inator"

Does anyone else struggle to remember all of this stuff? Tips? Do people take notes?

Jelena Simic
Jelena Simic
285 Points

Yes, omg I struggle too. But every time I look at it, it gets a microscopic amount easier and I see hope. No, I haven't been taking notes, but I'm going to start.

Mallik V
Mallik V
721 Points

def suggest(product_idea): if len(product_idea) <= 3: raise ValueError("Product idea should be longer. ") return product_idea +"inator"

i really struggled here

I really struggled with this one until I found this discussion. I don't think I'm understanding creating variables and I watched that video a couple of times too. This is not as easy as I taught or is it just me? ( ′~‵ )

OH MY GOD!!! I had it as

product_idea.len()

I'm such a bone head!!!