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 trialThierry Oberle
2,345 Pointssolution?
def just_right(astring):
if len(astring) < 5:
print("Your string is too short")
elif len(astring) > 5:
print("Your string is too long")
else:
return True
Whats wrong here?
Julian Gutierrez
19,201 Points*Markdown edited-JG
3 Answers
Steven Parker
231,271 PointsYour function doesn't always return anything.
It looks like you have print instead of return in a couple of the cases.
I managed to spot it with the code unformatted, but Leonard has a good point. In Python, indentation is crucial, but it cannot be seen unless the code is properly formatted.
Thierry Oberle
2,345 PointsSorry for not knowing how to post code. It's the first time I did that. How can I show the indentation the best way? Thanks for all your answers so far anyway!
leonardbode
Courses Plus Student 4,011 PointsThierry, if you just copy and paste your code in between the two lines, like in my previous comment, it will automatically format it with tabs.
def foo(x, y):
return x, y
Steven Parker
231,271 PointsThe posting instructions are in the Markdown Cheatsheet pop-up below the "Add an Answer" area.
So were you able to pass the challenge after changing your print lines into return?
Thierry Oberle
2,345 Pointsdef just_right(astring):
if len(astring) < 5:
print("Your string is too short")
elif len(astring) > 5:
print("Your string is too long")
else:
return True
Steven Parker
231,271 PointsGood formatting, but you still need to fix it to pass the challenge.
Thierry Oberle
2,345 PointsHi Steven sorry for not answering so long. Thanks for your advice! It worked with return instead of print. I didn't know that a print statement can be shown with return as well.
Steven Parker
231,271 PointsYou will be returning just the string, not the entire print statement. We don't really know how the strings will be used, though it does seem likely that they might be printed at some point.
leonardbode
Courses Plus Student 4,011 Pointsleonardbode
Courses Plus Student 4,011 PointsThierry, when posting code put it between the following lines:
```python
(Your code here)
```
Do this and I will help you.