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

Kevin Gamuzza
Kevin Gamuzza
3,547 Points

Check won`t work although my code works just fine in workspaces

The check does not accept my solution altough my code works just fine in workspaces. Can anyone help with a solution that works so that I can actually finish the course? Best regards

suggestinator.py
def suggest(product_idea,number_of_characters):
    if number_of_characters <= 3:
        raise ValueError ("More than 3 characters required")
    return(product_idea + "inator")
try:
    product_idea = input("What is your productidea?  ")
    number_of_characters = int(len(product_idea))
    product_suggestion = suggest(product_idea,number_of_characters)
except ValueError as err:
    print("Not a valid value!")
    print("({})".format(err)) 
else:
    print("Your product should be called: {}".format(product_suggestion))

2 Answers

Steven Parker
Steven Parker
231,269 Points

You only need to add a test and raise to the function, you won't need a "try", "except", "input" or "print".

And you must not change the number or type of argument that the function takes, the challenge validator will be testing it by calling with just one string argument.

Rahul Saini
Rahul Saini
4,611 Points

You really don't need to add another argument named: number_of_characters. You can use this.

def suggest(product_idea):
    number_of_characters = len(product_idea)
    if number_of_characters <= 3:
        raise ValueError ("More than 3 characters required")
    return(product_idea + "inator")