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

CESAR AGUILAR
seal-mask
.a{fill-rule:evenodd;}techdegree
CESAR AGUILAR
Python Development Techdegree Student 710 Points

i need help close to sloving the raising of a ValueError but i dont know what indentation error im doing wrong?

suggestinator.py
def suggest(product_idea):
    return product_idea + 'inator'
    raise a ValueError(Are you sure you don't understand? )
understand = input("Do you understand ")
   if understand != yes:
    raise a ValueError(Are you sure you don't get it? )
    return product_idea + 'inator'

2 Answers

## There are actually several things that are wrong with your code
def suggest(product_idea):
    # Your code will never go beyond this line because once the code reaches return it
    # just stop there and return whatever is passed to it
    # for this example, the code will execute return product_idea + 'inator' and stop
    # it will not go beyond that point
    return product_idea + 'inator'
    # when you raise any error, you do it this way,
    # raise ValueError
    # raise SyntaxError
    # etc
    # the way you did it, "raise a ValueError" is wrong syntax
    # there is no need there to be 'a', it should be just raise ValueError
    # also you need to surround your question with "" quotes
    # like this, raise a ValueError("Are you sure you don't understand? ")
    raise a ValueError(Are you sure you don't understand? )
# the following line is not properly intended
understand = input("Do you understand ")
   # yes is not surrounded by quotes, "yes"
   if understand != yes:
    # no quotes around question, also no need to raise ValueError here
    raise a ValueError(Are you sure you don't get it? )
    return product_idea + 'inator'



# This is what you need to complete the challenge
def suggest(product_idea):
    # Here we check to see if the string product_idea has less then 3 characters
    # if it does, we just raise the ValueError and the program stops there, it does not go to the return
    # if the if statement is false, it then returns the product_idea + "inator"
    if len(product_idea) < 3:
        raise ValueError
    return product_idea + "inator"

Be sure to use quotes when you type out your strings.

def suggest(product_idea):
    return product_idea + 'inator'
    raise a ValueError(Are you sure you don't understand? )  # < --- missing quotes here
understand = input("Do you understand ")
   if understand != yes:
    raise a ValueError(Are you sure you don't get it? ) # < --- missing quotes here
    return product_idea + 'inator'