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 trialjames mchugh
6,234 PointsNo idea
I reviewed the video on int() and division, but I'm not understanding how to put it all together
def sillyCase = (string):
len(string //2)
return string.upper
1 Answer
Steven Parker
231,269 PointsHere's a few pointers:
- when defining a function, the "=" symbol is not used. There should be nothing between the function name and the parentheses.
- the integer divide operator is being applied to the string itself instead of the length. It should be outside of the parentheses.
- you'll need an assignment to save the divided length so you can use it in later steps
- you may want to use slices with the computed half length to separate the first and second parts
- Python is very sensitive to indentation. The "return" line should not be any further over than the line above it.
- when calling a function (such as "upper"), the name must be followed by parentheses
- instead of applying "upper" to the whole string, you'll need to apply it to half of the string, and apply "lower" to the other part
- you can join the converted parts back together with concatenation (using the "+" symbol)
james mchugh
6,234 Pointsjames mchugh
6,234 PointsSteven, I took a break for a few months and maybe I forgot a few things. Do happen to know where I would find the section on assignments. ie. this part of your instructions. "you'll need an assignment to save the divided length so you can use it in later steps". I wrote it like this:
def sillyCase(string): (string) //2 = divided_in_half
Also I'm not sure how to name the first and second half Thank you for your help.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsYou can't divide a string by a number, you will probably need to use a slice or a string funciton to separate the string into 2 pieces.
And an assignment is simply putting a variable name on the left side of an equal sign ("="), and what you want that variable to hold on the right. For example:
half = len(string) // 2 # this assigns the value of half the length to the variable "half"