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

Greg Maddox
Greg Maddox
1,471 Points

having a lot of problems with the consistency of the modules and what im getting in the python shell.

This is the second module that i have had write answers in the python shell, but get a "didn't get the right value", or "Try again" in the comments. not sure what the deal is.

sillycase.py
def sillycase(string1):
    str_length = len(string1)
    if (str_length % 2) == 0:
        first = string1[:(int(str_length / 2))].lower()
        last = string1[-int((str_length / 2)):].upper()
        word = first + last
        print(word)
    else:
        first = string1[:int((str_length // 2))].lower()
        last = string1[-(int((str_length // 2)+1)):].upper()
        word = first + last
        print(word)

1 Answer

Steven Parker
Steven Parker
231,269 Points

It looks like you're pretty close, here's a few hints:

  • one method will work for all cases, even and odd lengths don't need to be handled separately
  • the function should return the modified word
  • you won't need to "print" anything
  • you can make the code more compact ("DRY") by computing half the length to start with