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

not sure where gettting wrong :/

what m i missing?

3 Answers

#Hello Sahil, heres your solution

def just_right(string):                   #in this line, you create the function just_right, it takes 1 argument
  if len(string) < 5:                     #here, you see if the length of the string is smaller then 5
    return "Your string is too short"     #if so, it returns the string "Your string is too short"
  elif len(string) > 5:                   #if the first condition is false, you then go on to see if the string is longer than 5 characters
    return "Your string is too long"      #is so, it returns the string "Your string is too long"
  else:                                   #if neither of the 2 statements above are true, then your string must be 5 characters long
    return True                           #it then returns True

It's helpful if you paste in the code you are struggling with, but...
1 make sure you create the function which takes a string parameter in the parentheses
2 use the len() function to find the length of the string parameter
3 use an if else branch to determine if the string more or less than 5 characters
good luck!

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