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

Andrew Clough
Andrew Clough
2,557 Points

sillycase

I run this though the ripple and it doesn't what the challenge is asking me to do. The prompt is asking for a function with a single string as an argument to be split in half and making the first half of the word lowered and the second half is upper. I got this code off of another "get help" question, and cleaned it up to make it easier to understand and its not working.

sillycase.py
def sillycase(word = str(input("enter word >" ))):

    length = len(word)
    half = length // 2

    word1 = "".join(word[:half]).lower()
    word2 = "".join(word[half:]).upper()

    returned_word = word1 + word2
    print(returned_word)

sillycase()

2 Answers

Sebastiaan van Vugt
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sebastiaan van Vugt
Python Development Techdegree Graduate 13,554 Points

Hi Andrew You were almost there. You don't need to use the join function since, when you are assigning your variables word1 and word2, you do not want to join any strings but merely capture matching halves from each end and turn them into upper or lower case:

    word1 = word[:half].lower()
    word2 = word[half:].upper()

Change this and it works :)

Andrew Clough
Andrew Clough
2,557 Points

I adjusted the code and removed the join() function. It's still is not working. I did double check it in my ripple and it still pass there, but not in the challenge.

Sebastiaan van Vugt
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sebastiaan van Vugt
Python Development Techdegree Graduate 13,554 Points

Hi again. Sorry, I just checked whether it worked and not if it passed. Two more modifications will make your script simpler and make it pass. First of all, they are asking that this function takes a single argument so the fancy input method is not required for the function to work (i.e. "def sillycase(word)" will suffice). And then, as usual, they ask the result to be returned and not printed (i.e. "return returned_word")

Finally, you also do not need to call the function to pass since that isn't asked either. Therefore the following script will work:

def sillycase(word):

    length = len(word)
    half = length // 2

    word1 = word[:half].lower()
    word2 = word[half:].upper()

    returned_word = word1 + word2
    return returned_word