Python Python Collections (2016, retired 2019) Slices sillyCase

james mchugh
james mchugh
5,506 Points

No idea

I reviewed the video on int() and division, but I'm not understanding how to put it all together

sillycase.py
def sillyCase = (string):
     len(string //2)
        return string.upper

1 Answer

Steven Parker
Steven Parker
171,141 Points

Here'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
james mchugh
5,506 Points

Steven, 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
Steven Parker
171,141 Points

You 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"