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

Stuck on Task 1

This runs fine outside of the task. I'm not sure what they are looking for here.

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

2 Answers

Daniel Bourke
Daniel Bourke
3,870 Points

Your code is perfect, except that the challenge asks for return statements rather than print statements.

I think if you swap those out you should be fine :)

Otherwise, you may also have to remove your defined string variable "abcde", that might cause some issues with the challenge as well.

Yes, just swapped the print for returns, and that worked! Silly miss read. Thank you Daniel

Josue Ipina
Josue Ipina
19,212 Points

First, the challenge only requires you to write the function, so the string variable on line 1 is unnecessary. Now, inside the function, you printed the message instead of just returning. And finally, you don't need to call the function, so you can delete the last line.