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 (Retired) Slices sillyCase

selcuk baran
selcuk baran
3,526 Points

what is the problem with the code?

def sillycase(a): x=a[:index(len(a)/2)].lower() y=a[index(len(a)/2):].upper() z=x+y return z

silly.py
# The first half of the string, rounded with round(), should be lowercased.
# The second half should be uppercased.
# E.g. "Treehouse" should come back as "treeHOUSE"
def sillycase(a):
    x=a[:index(len(a)/2)].lower()
    y=a[index(len(a)/2):].upper()
    z=x+y
    return z

2 Answers

Hi Selcuk,

I had trouble with this one a few days ago as well. I found that the issue was we have to use the round function when are dividing the length of the string to avoid getting floats. Also, you don't need to create variables for this function- you can simply concatenate the two strings. Hope this helps and happy coding! :)

def sillycase(string):
    return string[:round(len(string)/2)].lower() + string[round(len(string)/2):].upper()