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 trialEmilio Andere
495 Pointsis this correct, why not
do I change the function call?
def just_right(string):
just_right = 'abcdefg'
if len string < 5:
print("Your string is too short")
elif:
string > 5:
print("Your string is too long")
else:
return(True)
just_right()
Mathew Tran
Courses Plus Student 10,205 PointsHey Emilio,
You are almost there! Just a few things to brush up on :)
I'll give you some pointers based off your code and the challenge:
- You have defined just_right as a function and then you attempted to assign it a value. I am not sure what that will do exactly -- but I ran your code and it ran just fine! -- you may want to re-evaluate what you are attempting to do in that line
- Challenge says to return "Your string is too short / long", you have them printing but not being returned
- To use the len function it takes in an argument i.e. len("Emilio") # => returns 6
- Syntax for your return is a little bit off, it should be return <value>
- Your function, "just_right" takes in a parameter, but you have not supplied it one. i.e. just_right("emilio"),the just_right function takes in the "emilio" parameter to do whatever processing you specified in your function definition
- For your else if, the conditional logic needs to be placed before the colon. "Else if" is to specify another condition from which to branch off of, and else will catch anything else if the statements before fall through and evaluate to false
age = 20
if(age > 20):
// do something
elif(age < 20):
// do something
else:
// do something
As a general practice (in my opinion), try to iteratively solve a problem if you know you feel unsure.
My approach would be:
- Create a function that takes in a param that can return True
- Modify that function to do some processing, if the length of the parameter is higher than an amount, return "x"
- Modify that function to do the other processing task, if length is lower than an amount, return "y"
Good Luck! And Hope this helps!
Matt.
Julian Cardona
Python Web Development Techdegree Student 4,894 PointsI get it. The first error I can see is that you set just_right equal to some string in the second line of code. I'm pretty sure you don't want that. If the string you are trying to check the length on is 'abcdefg' it should go inside the parenthesis like so: just_right('abcdefg'). That is what will check the length. Furthermore the elif keyword if wrongly formatted. Make sure your semi colon is in the right spot. Also, check that you are using the len() function correctly.
1 Answer
Todd Anderson
4,260 PointsHi!
In this challenge you don't need to create a string called just_right, but just check the string being passed in as a parameter. For the length method to work you need to type it next to your variable with parens around it like this len(string). Finally you want to return not print on each of your conditional statements. You can just type return "Your string is too long", etc. When you return true at the end you don't need the parens, but you do need the uppercase T. You're almost there!!!
Julian Cardona
Python Web Development Techdegree Student 4,894 PointsJulian Cardona
Python Web Development Techdegree Student 4,894 PointsNot sure what you are trying to accomplish with the function. I am also semi new to python but I might be able to help.