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

Igor Ozherelyev
Igor Ozherelyev
2,052 Points

can't see what's wrong with my code. It showing exceptions all the time

Does it work well?

suggestinator.py
def suggest(product_idea):
    If len(product_idea) < 3:
        raise ValueError("is less than 3 characters long?")
    return product_idea + "inator"

2 Answers

Steven Parker
Steven Parker
231,275 Points

Python is case-sensitive. You wrote "If" (capital "I"), but it should be "if" (lower-case).

Igor Ozherelyev
Igor Ozherelyev
2,052 Points

Thanks. Fixed it. Still, have two exceptions: Traceback (most recent call last): File "", line 23, in test_exception_not_raised File "/workdir/utils/challenge.py", line 24, in execute_source exec(src) File "", line 3 if len(product_idea) < 3: ^ TabError: inconsistent use of tabs and spaces in indentation

Double checked all the spaces. Can't find the reason for this exception.

Steven Parker
Steven Parker
231,275 Points

I can't really check that without having the code formatted for Markdown (like the first example). But I do know that Python will work with tabs or spaces, but you can't mix them in the same file.

Igor Ozherelyev
Igor Ozherelyev
2,052 Points

Yeah, that was the reason. I used the tab instead of spaces in one file. Thanks so much for your help! 🙌