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 trialRoland Vas
1,967 PointsMy function argument if no brackets used acts as an undefined variable. Tried bypassing it with try: but no good
if i just add any value of characters it will be an undefined variable that doesn't exist... can't bypass that with the try and except function because I don't know what to write inside them
Any leads that may lead me to the answer would be great. Thank you
def just_right(arg):
if len(str(arg)) < 5:
print("Your string is too short")
elif len(str(arg)) > 5:
print("Your string is too long")
else:
return True
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Roland,
There's just 2 things:
The first is a syntax error. I'm not sure why you are adding str
when checking the length of your passed in value, which you named arg
. It should just be len(arg)
.
The second is just the result of the very strict code checker of the challenges. It asks you to return the strings "... too long" etc, and you are using the print
method.
So you are very close:
def just_right(arg):
if len(arg) < 5:
return("Your string is too short")
elif len(arg) > 5:
return("Your string is too long")
else:
return True
Keep Coding! :)
Roland Vas
1,967 PointsThank you Jason!