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

Kervin Bruce
Kervin Bruce
5,409 Points

I need a hint

I've tried a bunch of scripts for this" challenge "String length". but can't get it. create a new function named just_right that takes a single argument, a string. what does it mean a string as single argument? ex: (' '), str(), ('anyword'), (anyword) could I get a hint.

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

1 Answer

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,850 Points

Hey Kervin,

When you define a function, you can provide one or more parameters (you can think of a parameter as a variable that you want available to the code inside your function; then, when you call the function you can pass value(s) that are then assigned to the parameter(s). There are several types of values you can pass (e.g. Numbers, Strings). A string is anything between a set of quotation marks (i.e. ""). In this case you want to provide one parameter to your function, which will be assigned a string value. You can name the parameter whatever you want, but it should be sensical (str is a fine choice).

Here is a quick example:

def myFunction(parameter):
    return parameter

myFunction(123)  # returns 123
myFunction("boats") # returns 'boats'
myFunction(True) # returns True

In the above case, whatever I pass to myFunction, will simply be returned. I could also rename parameter to whatever makes sense within the context of myFunction.

Hope this helps; if not I can try to elaborate or be more clear.

Best, Clayton

P.S.

Here are some links to references that may be helpful.

Kervin Bruce
Kervin Bruce
5,409 Points

Thank you very much Mr. Clayton. I finally got it not difficult at all. you've been a great help, thanks!