Search code examples
python-3.xfunctionconcatenationuppercaselowercase

Using a function to split a word and then upper and lower the word


i'm trying to create a function that will take a word and return the first half in Upper case and the second half in lower case and i can't seem to get it quite right. feels like i need to split the word into two pieces and with them separate apply the upper and lower and then concatenate them together.

this is what i've tried so far, with no success.

def upper_lower (plain):
upper = str.upper(plain[0: len(plain) // 2])
lower = str.lower(plain[len(plain) // 2: -1])
return upper + lower

Solution

  • You're cutting off the last character in the string.

    Replace this

    lower = str.lower(plain[len(plain) // 2: -1])
    

    With this

    lower = str.lower(plain[len(plain) // 2:])