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

Kostas Stankevicius
Kostas Stankevicius
7,169 Points

Cant seem to find whats wrong with my function

Thanks for you help !

sillycase.py
def sillycase(string):
    half = len(string) // 2
    first = string[:one].lower()
    second = string[one:].upper()
    result = first + second
    return result

3 Answers

You defined the half variable but never used it. Once you put the half variable in the slices it works.

def sillycase(string):
    half = len(string) // 2
    first = string[:half].lower()
    second = string[half:].upper()
    result = first + second
    return result
andren
andren
28,558 Points

You just have a typo. When slicing the string you reference a variable called one which does not exist in your code. If you replace one with half which I assume is what you meant to type. Like this:

def sillycase(string):
    half = len(string) // 2
    first = string[:half].lower()
    second = string[half:].upper()
    result = first + second
    return result

Then your code will work.

Kostas Stankevicius
Kostas Stankevicius
7,169 Points

Thanks a lot, Andren and Brian. My variable for half length was originally called one :( silly mistake