Python Python Collections Slices sillyCase

Andrew Clough
Andrew Clough
2,430 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
Sebastiaan van Vugt
3,466 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,430 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
Sebastiaan van Vugt
3,466 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