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 trialMaggie Wolff
495 Pointspython basics challenge task 1 of 1 "string length"
I can't figure out how to even start it, could some one reword the question, or give me a clue on how to do this?
3 Answers
Josh Keenan
20,315 PointsHey Maggie, create a function that takes an argument, which is a string.
Then you need to check how long the string is.
If it is longer than 5 characters do x
If it is shorter than 5 characters do y
Anything else, just return True.
If you need any more help just let me know!
Josh Keenan
20,315 Pointsdef just_right(argument): # creating the function with an argument,
# this argument is replaced with the string that the test will pass in
if len(argument) < 5: # IF the length of the string is less that 5 characters DO:
return "Your string is too short"
elif len(argument) > 5: # ELSE IF the length of the string is greater than 5 characters DO:
return "Your string is too long"
else:
return True # If it is anything else (5 exactly), return True
Here's my solution, I explain each line, feel free to ask me any questions that you might have about it!
Maggie Wolff
495 Pointsok, so i don't really know what you, or the question means by 'argument'
Josh Keenan
20,315 PointsAn argument is just the value you pass into the parentheses (), now when you create a function it doesn't run, it can be run by calling it but you are just creating the outline for it.
You are telling the function to expect a string, this string can be anything and argument is just a name for it in this instance but you could use anything for it. The name is simply symbolic, so in this case the argument is actually called argument.
Does that help?
Maggie Wolff
495 PointsMaggie Wolff
495 Pointsok so, I do have another question...
I can't figure out what's wrong with this.
Greg Kaleka
39,021 PointsGreg Kaleka
39,021 PointsHi Maggie - don't print; return!
Other than that, your code looks right. I made some formatting fixes. You should use backtics (`), not apostrophes (') to surround your code. You also need to put them on a new line before and after your code. Lastly, you can add the language you're using to get syntax highlighting. Here's what it looks like:
```python
[your code goes in here]
```