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

Corey Buckley
Corey Buckley
1,257 Points

Output is correct (I think) but I'm being told otherwise

Its putting in 'sillycase' and my output is 'sillYCASE' but its says its not getting the right output.

sillycase.py
def sillycase(word):
    half_point = len(word) // 2
    word_as_list = list(word)
    word_as_list[half_point:] = word[half_point:].upper()
    word = "".join(word_as_list)
    print(word)

1 Answer

John Lack-Wilson
John Lack-Wilson
8,181 Points

I think perhaps you're overthinking this a little.

This is what the challenge is looking for:

  • The function takes ANY word as an argument and makes the first half lower case, and the second half of the word uppercase
  • It returns the result of the modified word

Potentially the first step could be to change the first half of the word to lower case and store it in a variable. Heres a simple example:

    def lower_first_half(word):
        first_half = word[:len(word)//2].lower()

Then the second step could be to change the second half of the word in a variable as upper case using the .upper() method. The process for the second_half of the word would be the same except for changing where the word is sliced.

Finally you could return the concatenation of these two halves.

Corey Buckley
Corey Buckley
1,257 Points

Changed it so the it also changes the first half of the letters to .lower incase any of them are uppercase and returned the word at the end and it worked. Thanks alot! :D