Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Slices sillyCase

arielp
arielp
3,516 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
3,516 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