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 trialSabaa Talal
Courses Plus Student 733 PointsFor a function, how to make the function result return (String)
(Create a new function named just_right that takes a single argument, a string. If the length of the string is less than five characters, return "Your string is too short". If the string is longer than five characters, return "Your string is too long". Otherwise, just return True.) This was the question I tried this code but it did not work can you help me recognize the problem with it?
def just_right(string):
if len(string)<5:
return ("your string is too short")
elif len(String)>5:
return ("your string is too long")
else:
return True
1 Answer
Michael Hulet
47,913 PointsYou have a small typo in your elif
statement. Remember that Python is case-sensitive, so it matters whether you type a capital or lowercase letter in all of your symbols. A variable named example
is entirely different than another variable named Example
. If you look in your elif
statement, you wrote String
with a capital "S", but the parameter's name is "string" with a lowercase "s". Also, you'll need to capitalize the "Y" in "Your" at the beginning of both strings you're return
ing. That's not Python caring about case there, because it's in a string literal. Python doesn't care about casing about characters inside a string. You'll need to capitalize both "Y"s because that's what Treehouse's challenge is expecting. Once you fix those issues, you should be good to go!