Python Python Collections (2016, retired 2019) Slices sillyCase

Michael Morale
Michael Morale
2,701 Points

Sillycase business.

I understand what it's asking, but I don't really know how to put it down. I know to use the (//2) to divide the word as well as the .upper and .lower but that's all I got. I know the int( function but not sure how it applies here. Any pointers?

sillycase.py
def sillycase(word):
    (//2 word.upper) + (//2 word.lower)

2 Answers

Seth Gorham
Seth Gorham
1,629 Points

Hi Michael, I was able to get this to work by using the len() function and slices.

word = "Revolution"
# Can't divide a string by an integer, so we get half the length
halfway = len(word) // 2
# Then use the halfway as an index in a slice, adding the upper or lower functions to the end
word[0:halfway].lower()
word[halfway:].upper()

A lot of this was trial and error running individual commands in the workspace.

Hope this helps and good luck!

Michael Morale
Michael Morale
2,701 Points

I tried that and couldn't get it to work.