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 trialwesley jackson
2,436 Pointsstrlen.py
Hi, My code works correctly in isolation but not passing. I would appreciate any pointers as to where I am going wrong. Thank you
def just_right(str):
num =int(str)
if num < 5:
return("your string is too short")
elif num > 5:
return("Yor string is too long")
else:
return True
1 Answer
doesitmatter
12,885 PointsHi wesley jackson,
To get the length we use len(str)
. With int(str)
we convert a string to an integer. For the rest, you need to literally return the text which they asked for. The rest is good though.
def just_right(str):
num =len(str)
if num < 5:
return("Your string is too short")
elif num > 5:
return("Your string is too long")
else:
return True
I hope this helped!
wesley jackson
2,436 Pointswesley jackson
2,436 PointsThank you First, truly appreciate your answer and swift response.