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 trialDustin Asevedo
1,367 Pointskeep getting SyntaxError
working on this challenge task it reads: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.
Was wondering what i did wrong to get a SyntaxError, and if my code is even near what it wants
def just_right('abcdefg'):
if 'abcdefg' < [4]:
return "Your string is too short"
elif:
'abcdefg' > [4]:
return "Your string is too long"
else:
return True
1 Answer
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou just need to tweak a few things. first, while the function takes a string, your parameter isn't a string, it's just a parameter, it can represent anything you feed it, so remove the quotes around 'abcdefg'. it doesn't have to be a string to accept a string when called. you need to use the len function like len(myVariable) which will return the length of its argument. this is what you compare to 5, which does not need to be in []. then your elif doesn't take a colon right after like else does, it needs another condition to test, so bring the line below up so it's elif len(myVar) > 5: the colon goes after the condition like the if line.
Dustin Asevedo
1,367 PointsDustin Asevedo
1,367 PointsThanks a ton man