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

Kennedy Malonga
Kennedy Malonga
22,856 Points

Can you please raise a ValueError if the product_idea is less than 3 characters long? product_idea is a string. Thanks i

where should i test the length of the string instead of the string itself will int() be needed anywhere

suggestinator.py
def suggest(product_idea):
    if product_idea < 3:
        raise ValueError("characters too short")
    return product_idea + "inator"

4 Answers

Kennedy Malonga
Kennedy Malonga
22,856 Points

finally got it right by mistake

def suggest(product_idea): if len(product_idea) < 3: raise ValueError("characters too short") return product_idea + "inator"

Steven Parker
Steven Parker
231,269 Points

No "mistake" there – you got it!   :+1:

Lindsey Mote
seal-mask
.a{fill-rule:evenodd;}techdegree
Lindsey Mote
Data Analysis Techdegree Student 1,148 Points

I'm stuck on this one as well! I used the same code as suggested by Kennedy above and got the following error: AssertionError: None != 'baconinator' : I passed in 'bacon' and expected 'baconinator', but got 'None'

Steven Parker
Steven Parker
231,269 Points

Try creating a fresh question where your exact code will be shown.

Did we ever figure this out? I just got stuck here as well.

Steven Parker
Steven Parker
231,269 Points

Yea, Kennedy realized he was testing the string itself instead of the length of the string. He just forgot to use Markdown formatting on the code in his answer.

Steven Parker
Steven Parker
231,269 Points

You won't need int(), but you might need to use the len() function.   :wink:

I'm running into an issue where I keep getting an EOF error on line 5 which is my input line and I'm assuming it has something to do with product_idea being a string can someone please hint me towards what is wrong with it?

def suggest(product_idea): return product_idea + "inator"

product_idea = input("whats your product idea? ")

if len(product_idea) < 3: raise ValueError("please 3 characters or more")

nevermind i r just got it i was doing too much