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 trialSufian Javed
523 PointsNot 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.
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
Alexander Davison
65,469 Pointslen
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
Note that len
counts spaces/tabs/punctuation as characters, too. So this means len('! ? $')
would return 5.
I hope this helps!
Happy coding! ~Alex
Sufian Javed
523 PointsSufian Javed
523 PointsThank you! I finally got it :)
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsNo problem :D