"AJAX Basics (retiring)" was retired on February 5, 2020. You are now viewing the recommended replacement.

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

Andrew Helton
Andrew Helton
4,681 Points

Works in Python Shell, but not accepted in Code Challenge. Any ideas why?

I'm just needing to understand why my code isn't being accepted as a good answer. I've tested it out in Workspaces and it works perfectly fine.

Having said that, I am tired so maybe I'm missing a typo or something...

P.S. I've tried submitting with and without the defined variable and function call. Neither answers are accepted and no hints are given as to why my answer is wrong.

strlen.py
my_string = "Hi"

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

just_right(my_string)

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Your code is mostly correct. But you need to change the TWO print statement into return to pass the challenge.

Andrew Helton
Andrew Helton
4,681 Points

Thanks, William. I didn't key in on the word 'return' in the problem. Appreciate the help!