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

Joshua Tiedtke
Joshua Tiedtke
5,647 Points

Don't know what's wrong (sillyCase).

I have some difficulties approaching this task. This is the best I can come up with but it doesn't work. What is my mistake here and how can I correct it?

sillycase.py
def sillycase(word):
    m = int(len(word))//2
    first_half = word[:m]
    second_half = word[m+1:]
    new_word = first_half.lower() + second_half.upper()
    return new_word

1 Answer

Stuart Wright
Stuart Wright
41,120 Points

You're so close. Where you've used [m+1:], you need simply [m:].

This is because the element at index m is not included in [:m], because of the way Python slicing works. So you need to include element at index m in your second_half variable.

Joshua Tiedtke
Joshua Tiedtke
5,647 Points

Oh that was really close :D Thanks for the help!