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

Catherine Grace de Leon
Catherine Grace de Leon
3,153 Points

Hi! I'm having trouble with the sillycase slice challenge, and I'm not sure where I'm getting it wrong.

def sillycase(string): first_half = int(len(string) / 2 - 1) #get index of first half second_half = int(len(string) - 1) #get index of second half

new_string = string[:first_half].lower() + string[:second_half].upper() #combine the two into a single string
return new_string
sillycase.py
def sillycase(string):
    first_half = int(len(string) / 2 - 1) #get index of first half
    second_half = int(len(string) - 1) #get index of second half

    new_string = string[:first_half].lower() + string[:second_half].upper() #combine the two into a single string
    return new_string

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

You math was a bit off, and only one index is needed for both slices:

    first_half = int(len(string) / 2) #<-- corrected math
    new_string = string[:first_half].lower() + string[first_half:].upper()  # <-- used same value for both slices