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

Marcilio Leite Neto
Marcilio Leite Neto
16,465 Points

couldn't find sillycase

The exercise checker is not finding my sillycase function. Any ideas?

Thanks :D

sillycase.py
def sillycase(string):
    pos = ceil(len(string) / 2)
    new_string = string[:pos].lower() + string[pos:].upper()
    return new_string

3 Answers

Alex Arzamendi
Alex Arzamendi
10,042 Points

I have not gotten up to that part yet, but I managed to solve it with the following script

def sillycase(stringV):
  stringLen = len(stringV)
  firstHalf = stringV[0:int((stringLen / 2))].lower()
  secondHalf = stringV[int((stringLen/2)):].upper()

  return firstHalf + secondHalf
Marcilio Leite Neto
Marcilio Leite Neto
16,465 Points

Well, it worked :D

Thanks Alex! It's still weird though, because my code worked at the workspace and also the error said that it didn't find the function, not that the result was wrong...

Thanks again for your help!

Hi Marcilio,

The error message is misleading in this case.

The problem was with the ceil() function. It's part of the math module.

So you have to import the math module and then use math.ceil()

However, this won't pass all the test cases because it will always put the middle letter (for odd length strings) in the first half. But looking at the example "Treehouse", it wants the middle letter 'h' with the second half. Expected result = "treeHOUSE"

So rather than rounding up on .5 which is what ceil() will do, you need to truncate or round down on .5

int() as Alex used, or math.floor() will both accomplish this.