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

Enzo Cnop
Enzo Cnop
5,157 Points

Bummer! Couldn't find 'sillycase'. Why is this occurring?

def sillycase(string):
    count = round(len(string)/2)
    first_half = (string[:mid]).lower()
    second_half = (string[mid:]).upper()
    return first_half + second_half

Above is my code. Why is the compiler telling me 'couldn't find sillycase'? Also, a bunch of examples in questions use various stand in figures for the "(string[:mid]).lower()" portion. Some use 'half' some use 'middle' some use 'mid'. I'm confused as to how python knows these words / if I missed something in the video that explains how you can substitute integers for other variables in the slice notation.

sillycase.py
def sillycase(string):
    count = round(len(string)/2)
    first_half = (string[:mid]).lower()
    second_half = (string[mid:]).upper()
    return first_half + second_half

1 Answer

mid is a variable. You want to declare mid in the first line of your function instead of count, which will fix your issue. You can always substitute an integer for a variable. The slice notation is irrelevant to whether you could use variables or not.

Enzo Cnop
Enzo Cnop
5,157 Points

Thank you! I didn't realize you could use variables in slice notation. This was the missing piece.