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

Julian Eysmont
Julian Eysmont
496 Points

how to count characters in strings?

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

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Julian Eysmont! Counting the number of characters in a string is fairly straightforward. If you pass in the string to the len() function, it will return the number of characters. For instance:

name = "Julian"
print(len(name))

This will print out the number 6 because there are 6 characters in "Julian". I think what you're meaning to do is ask:

if len(product_idea) < 3:

Hope this helps! :sparkles: