Python Python Basics Functions and Looping Raise an Exception

Blessing Nyamayedenga
Blessing Nyamayedenga
6,163 Points

hey guys , please I need help I seem not to get this right im getting an EOFError

suggestinator.py
def suggest(product_idea):
    return product_idea + "inator"
    if len.product_idea < 3:
        raise ValueError ("please enter longer name ")
try:
    input("please enter your suggestion")
except ValueError as err :
    print("{}" .format(err))
else:
    print(product_idea)

suggest()

2 Answers

Josh Keenan
Josh Keenan
17,380 Points

To complete the challenge this is all you need:

def suggest(product_idea):
    if len(product_idea) < 3:
        raise ValueError
    return product_idea + "inator"

Firstly, you need to check if it is valid before you return the new string, you don't need to output anything if the product idea is less than 3 characters, only raise the exception.

Blessing Nyamayedenga
Blessing Nyamayedenga
6,163 Points

Traceback (most recent call last): File "", line 32, in test_exception_raised File "", line 2, in suggest AttributeError: 'builtin_function_or_method' object has no attribute 'product_idea'

Josh Keenan
Josh Keenan
17,380 Points

Even with my code? You should have just those 4 lines and nothing more

Josh Keenan
Josh Keenan
17,380 Points

apologies I misread your code, you used the len function incorrectly, it is called by using parentheses at the end, not a dot.

len(my_string)

This will get the length of the variable my_string