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 trialMayibongwe Ngwenya
1,425 PointsWhats wrong with my code
I keep getting the following error TypeError: '<' not supported between instances of 'str' and 'int'
4 Answers
Kent Åsvang
18,823 PointsYou need to convert your string to an integer, the 'smaller than' ( '<' ) comparison operator don't work with strings.
Mayibongwe Ngwenya
1,425 Pointsit's the raise an exception challenge in python basics we're trying to raise a ValueError exception if the product idea, which the user inputs is less the 3 characters long
def suggest(product_idea):
if int(product_idea) < 3:
raise ValueError
return product_idea + "inator"
Kent Åsvang
18,823 PointsOkey, python has a built-in function called len(), it takes a string as argument, and returns its length as an integer, which can be used with the comparison-operator.
def suggest(product_idea):
if len(product_idea) < 3:
raise ValueError
return product_idea + "inator
Mayibongwe Ngwenya
1,425 Pointsthank you
erilope
Courses Plus Student 364 Pointslen is the action that makes sure to count the words right? If that makes sense I am literally just starting out, and I am loving treehouse over codecademy but somethings I still need help on.
Mayibongwe Ngwenya
1,425 PointsMayibongwe Ngwenya
1,425 Pointswhen i try to convert the string to an integer with int() i get the following error ValueError: invalid literal for int() with base 10: 'bacon'
Kent Åsvang
18,823 PointsKent Åsvang
18,823 PointsIf you tell me what the challenge is or if you copy/paste your code I could try and see if I can help you to see whats wrong