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

Sufian Javed
Sufian Javed
523 Points

Not clearly understanding the concept.

Could someone please tell me what is wrong with this code. I am a complete beginner and am having understanding certain concepts. I tried to use the .len property to target the challenge but it did not work.

suggestinator.py
def suggest(product_idea):
    if product_idea.len < 3:
        raise ValueError("Please enter a name with atleast three characters.")
    return product_idea + "inator"

1 Answer

len is a function that takes in a string (actually, it takes in any kind of iterable, but that is covered in another course), and it "returns" (spits out) a number, the length of the string (or iterable).

For instance...

(Pretend I'm in the Python Shell.)

>>> len('abc')
3
>>> len('hello world')
11
>>> len('1 2 3')
5
>>> len('  ')
2

:warning: Note that len counts spaces/tabs/punctuation as characters, too. So this means len('! ? $') would return 5.

I hope this helps! :grin:

Happy coding! :zap: ~Alex

Sufian Javed
Sufian Javed
523 Points

Thank you! I finally got it :)

No problem :D