Python Python Collections (2016, retired 2019) Slices sillyCase

help please

help me
def sillycase (single):
    name[-2:] = single
    new = int(name[-2:])/2
    go = new.lowecase +  new.uppercase
    return go

1 Answer


This is my solution

def sillycase(single):
    firstHalf = single[:len(single) // 2]
    secondHalf = single[len(single) // 2:]
    go = firstHalf.lower() +  secondHalf.upper()
    return go

As you can see, the way to lowercase a string is with the function lower(), and upper() to uppercase a string. Then when you slice the string, you can slice the first half by starting at the start of the string and ending at the rounded half index with len(single). To get the second half you instead start at the rounded half index with len(single) and stop at the end of the string.