Python Python Basics Functions and Looping Raise an Exception

Randall Varasteh
seal-mask
.a{fill-rule:evenodd;}techdegree
Randall Varasteh
Python Development Techdegree Student 2,814 Points

Stuck on challenge

Not sure why this isn't working, please help.

suggestinator.py
def suggest(product_idea):
    if int(product_idea) < 3:
        raise ValueError("Must contain 3 or more characters.")
    else:
        return product_idea + "inator"

I think you should use len instead of int so you compare the lengh of the string instead of integer.

def suggest(product_idea):
    if len(product_idea) < 3:
        raise ValueError("Must contain 3 or more characters.")
    else:
        print(product_idea + "inator")
suggest("Idea")

2 Answers

Matik Zed
Matik Zed
11,491 Points

Hey Randall! I would try using len the python built-in instead of casting the string into an integer. That way you get the length of the string. :)

def suggest(product_idea):
    if len(product_idea) < 3:
        raise ValueError("Must contain 3 or more characters.")
    else:
        return product_idea + "inator"