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 trialEswar Ambati
890 PointsWhat do I need to do to correct this?
I am not sure as to why this is not working. Please can someone explain what I need to add or modify please thank you.
def suggest(product_idea):
try:
if len(product_idea) < 3:
raise ValueError("The product idea is less than 3 charcters long")
except ValueError as err:
print("Sorry but {}".format(err))
else:
return product_idea + "inator"
1 Answer
Grigorij Schleifer
10,365 PointsHi Eswar, you are working way too hard. For the challenge, you just need to check the length of the string argument and raise an exception if it is less than 3. After you did this, a return statement should follow. A try block is very neat but not needed for the challenge.
This one should work.
def suggest(product_idea):
if len(product_idea) < 3:
raise ValueError("The product idea is less than 3 charcters long")
return product_idea + "inator"
You can try this code in the workspace. It is very similar to what you have and has the user interaction that is sadly missing in the challenge interpreter
def suggest(product_idea):
while len(product_idea) < 3:
raise ValueError("Please type in something 3 characters or more.")
return product_idea + "inator"
try:
suggestion = input("What product idea were you thinking of? ")
newName = suggest(suggestion)
print("This should be your product idea name, {}".format(newName))
except ValueError as err:
print("{}".format(err))
I hope this helps
Eswar Ambati
890 PointsThank you very much!
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsYou are welcome!