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

Richard Stiehm
PLUS
Richard Stiehm
Courses Plus Student 12,817 Points

sillyCase???? Why doesn't this work?

Not sure how to answer this one it is getting rejected, but it does work on the command line and in IDE???

def sillycase(string): string = string.upper() print string[:len(string) / 2].lower() + string[len(string) /2:]

sillycase('SILLYcase')

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 string[:len(string) / 2].lower() + string[len(string) /2:]

3 Answers

Slices need to have integer indices, which is not guaranteed to be the case for

len(string)/2.

Try rounding it to and integer with

round(len(string)/2).

You'll also need to make sure you convert the second half of the string to uppercase. After you do both of those it should work.

You will need to add one to the half length of the string.

Richard Stiehm
PLUS
Richard Stiehm
Courses Plus Student 12,817 Points

Great thanks.... Makes sense about rounding. Also the silly.py file window doesn't have the code with uppercase....but the one I was actually using to test did.(the plain text above silly.py). Just forgot to paste back in