Python Python Collections Slices sillyCase

arielp
arielp
769 Points

def sillycase

Here I am stuck again unable to pass the challenge.

wrd = ["treehouse"]


def sillycase(word):
    for word in word:
        print word[:4] + word[-5:].upper()
        return


sillycase(wrd)

thanks in advance!

2 Answers

No need to loop here, you can accomplish this with string slicing.

def sillycase(s):
    return s[:len(s)//2].lower() + s[len(s)//2:].upper()
arielp
arielp
769 Points

I see, thanks.

// is the floor division operator. It returns the integral part of the quotient.

>>> 5 / 2.3
2.173913043478261
>>> 5 // 2.3
2.0