Python Python Basics Functions and Looping Raise an Exception

Julian Eysmont
Julian Eysmont
496 Points

how to count characters in strings?
def suggest(product_idea):
    if product_idea < len(3)
    raise ValueError("The name is too short")
    return product_idea + "inator"

1 Answer

Jennifer Nordell
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"

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: