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 trialRocco Soucie
1,018 PointsI don't know what I have to do for Raising Exceptions Quiz.
Hi, I'm Rocco! I am new to Python, and have been taking the Python Basics course. I have been at the coding problem for Raising Exceptions for a while now, and I'm not sure what I am supposed to do, and what I am missing, because when I "check work" it says I have two errors. I don't know if I am writing the complete code or just raising the ValueError.
def suggest(product_idea):
if product_idea <=3:
raise ValueError("Please more characters")
return product_idea + "inator"
try:
product_name = suggest(product_idea)
except ValueError:
print("{}")
else:
print("{}inator".format(product_idea)
2 Answers
Steven Parker
231,269 PointsYou're working way to hard! The challenge doesn't ask for a program to call the function, assign a new variable, catch the exception, or print anything.
You just need the "raise" statement and the test to control when it happens.
And in your test, instead of comparing the string itself, you probably want to check the length of the string.
Herman Morales
8,831 Pointsdo you have calculate the lenght to the word and compare and only raise the error, donΒ΄t make a try catch
def suggest(product_idea):
if len(product_idea) <=3:
raise ValueError("Please more characters")
return product_idea + "inator"
Steven Parker
231,269 PointsExplicit answers without any explanation are strongly discouraged by Treehouse and may be subject to redaction by staff or moderators.
Rocco Soucie
1,018 PointsRocco Soucie
1,018 PointsThank you so much! I overthought it and completely forgot about the length of the code. Thanks again!