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

what am i doing wrong

what am i doing wrong? can someone help me out

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(string):
  return sillycase(string.round)
string.lowercase()
string.uppercase()

1 Answer

Michael Pastran
Michael Pastran
4,727 Points

the problem your having is that first you need to get the middle point of the string. so lets say you had the word "love" the middle point would be the "o". but what happens if you had "loves"? the middle would be 2.5 right? since theres 5 letters. thats why you need to round the middle point. so that part would look like this

def sillycase(str):
  length = round(len(str)/2)

btw i just write str because it can be any string of type str.

then the part that deals with the return.

  return str[:length].lower() + str[length:].upper()

we are slicing the string that we passed. starting at the beginning and ending at the length. remember that length holds the middle point of the string. then we are just using the method .lower() to make it lower case. then we concatenate it to the second part of the string which would start at the length and go to the end [length:] and then we make that upper case. and thats the solution. hope that helped

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

I would caution against using "str" as a function parameter or local variable name since it is the name of the built-in class str(). Using "string" is acceptable.