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

Helen Brophy
Helen Brophy
6,736 Points

Everything I try results in an AssertionError, can someone please help?

Can someone please help me fix this?

suggestinator.py
def suggest(product_idea):
    if str(product_idea) < str(len('3')):
        raise ValueError("This is to short")
    return product_idea + "inator"

2 Answers

Helen Brophy
Helen Brophy
6,736 Points

Don't worry - solved it :-)

Antonio De Rose
Antonio De Rose
20,884 Points
def suggest(product_idea):
    if str(product_idea) < str(len('3')):# this is how you not check the length of a string
# you can just call in the len function surrounded the string with the paranthesis, checking against the direct value 3, itself will do, you have made it complex.
        raise ValueError("This is to short")
    return product_idea + "inator"
Helen Brophy
Helen Brophy
6,736 Points

If I remove the str() functions it returns "TypeError: '<' not supported between instances of 'str' and 'int'".

No matter what I try, this code does not work.