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

Joshua Stokes
Joshua Stokes
769 Points

Challenge Task - String Length (Answer not accepted in treehouse)

I'm having trouble completing this challenge task on string length. The code attached definitely works in a python interpreter, however treehouse doesn't like it. What am I doing wrong?

strlen.py
def just_right(string):
    if len(string) < 5:
        print("Your string is too short")
    elif len(string) > 5:
        print("Your string is too long")
    return True

1 Answer

For the first two messages ("you string is too long" and "your string is too short"), you only printed the messages so really if the function is called with the argument 6, this is was it'll happen:

  1. It will print out "You string is too short!"
  2. It will return True

So, to fix that, replace both print*s with a *return. :)

Good luck! ~alex

Joshua Stokes
Joshua Stokes
769 Points

Ok that works, but do you mean argument 6 as a string, so it looks like this... just_right("6") or something else.

No, I meant 6 as a number :)

I can't say "is this text greater than this number?" because it just doesn't make sense and strings are text :)

What's confusing is that you said the "argument 6" but the function is expecting a string to be passed in.

I think that's what Joshua was trying to get clarification on.

Joshua Stokes
Joshua Stokes
769 Points

Ok, I think I'm starting to understand you now, but just incase.

When you talk about argument 6, do you mean that instead of determining whether a string is equal to 5 characters, to determine whether a string is equal to 6 characters?

Update - Yes, what Jason said