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 trialPritam Pal
1,203 PointsSomeone please help me with this problem
I've made a function that creates brand new product names using "artificial intelligence".
I have a problem though, people keep on adding product ideas that are too short. It makes the suggestions look bad.
Can you please raise a ValueError if the product_idea is less than 3 characters long? product_idea is a string. Thanks in advance!
def suggest(product_idea):
return product_idea + "inator"
except ValueError:
if len(suggest) < 3:
print("Common man!")
3 Answers
Jeff Muday
Treehouse Moderator 28,722 PointsI think you are getting part of the idea correct, but we need to put things in the right order and raise an error. First, check if the product_idea length is less than 3-- if it is, raise an error... see below.
Kenneth really wants everyone to learn how to raise errors. It is a great coding convention and he will come back to it again and again. Learn it and live it!
Python is a fun language, best of luck on your journey!
def suggest(product_idea):
if len(product_idea) < 3: # check for length of less than 3
raise ValueError # raise a Value Error. Kenneth emphasizes raising errors in the lecture.
return product_idea + "inator"
Omar Hussien Khafagy
1,431 Pointsthank you
Richard Thomas
3,029 PointsWhy are we using len? why is it not stated in the task at all?
we just used if number_of_people <= 1:
now we're using if len(product_idea) < 3: randomly? Are you guys trying to discourage people into giving up? Every single task I do has some hidden language we haven't used in a few video's.
len is not even used during the two hints!!
Luke Walker
274 PointsThis was where I tripped up as well. I understand I had to do something to do with the length of reply but had no idea what or how I should create that in code.
Jeff Muday
Treehouse Moderator 28,722 PointsYou have demonstrated you are one of the more curious/creative types by coming into the forums to post your comments-- great work! Treehouse is a learning community and we learn from each other.
I find myself refering to the Teacher's notes, offical Python documentation, Stack Overflow, and other Internet resources when I get stuck.
When you get stuck on a challenge, don't let it frustrate you or stop your progress in learning, move forward. You can come back later and try a different approach. I find myself redoing some challenges just because they were interesting or to try different approaches.
Darin Codon
1,706 PointsLearning in this environment can be challenging; particularly when getting stuck on a problem you have little reference to interpret it through. This challenge has taken me a very long time to tackle and it's slowed my progress substantially.
Omar Hussien Khafagy
1,431 PointsThat is right It took a long time. To solve the problem. And I found out I'm not alone in not understanding. I was totally frustrated. That's the language. It's not easy to get started.
Omar Hussien Khafagy
1,431 Pointsok plz i solve this code too but get fail
Nick Kolarik
3,747 PointsNick Kolarik
3,747 PointsI think the conditional statement 'if len(suggest) <3 should be testing the length of the input variable instead. i.e. 'if len(product_idea) < 3: do something....