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 trial

Python Python Basics (2015) Number Game App String length

Thierry Oberle
Thierry Oberle
2,345 Points

solution?

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?

Thierry, when posting code put it between the following lines:

```python

(Your code here)

```

Do this and I will help you.

3 Answers

Steven Parker
Steven Parker
231,248 Points

Your 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
Thierry Oberle
2,345 Points

Sorry 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!

Thierry, 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
Steven Parker
231,248 Points

The posting instructions are in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:

So were you able to pass the challenge after changing your print lines into return?

Thierry Oberle
Thierry Oberle
2,345 Points
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
Steven Parker
Steven Parker
231,248 Points

Good formatting, but you still need to fix it to pass the challenge.

Thierry Oberle
Thierry Oberle
2,345 Points

Hi 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
Steven Parker
231,248 Points

You 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.