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

Christopher Flores
Christopher Flores
6,898 Points

do I even need to create a variable

I think I'm close but can't get it to work. Where is the problem? Without variable it still doesn't work.

suggestinator.py
def suggest(product_idea):
    product_idea = input("")
    if product_idea < 3:
        raise ValueError("more than 3 characters needed")
    return product_idea + "inator"

2 Answers

Josh Keenan
Josh Keenan
20,315 Points

Firstly, you don't need the variable but I think you get that, the string will be passed into the function and we just need to work with that. The issue you have had other than that is here:

if product_idea < 3:

Product idea is coming in as a string, which means this statement makes no sense, a string can't be compared to an integer. However there is a function that can get the length of a string and tell you that value, this is what you need. You can use len() to get the length of a string, using this with product_idea you should be able to get through this! I believe in you, good luck!

Feel free to ask any other questions about this if you need to.

Christopher Flores
Christopher Flores
6,898 Points

took me a little while but eventually I got it. Thanks for the help!

Josh Keenan
Josh Keenan
20,315 Points

Glad you got it, don't be afraid to ask any questions if you don't understand anything! You got this!