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

I got the sillycase challenge to work but the checker is not recognizing that the challenge works.

input_word = input("Type in a word:")

def sillycase(input_word): for x in input_word: return input_word

get_length = len(input_word) word_length = int(get_length) half_of_word = word_length//2 first_half_of_word = input_word[0:half_of_word] second_half_of_word = input_word[half_of_word:-1] last_letter = input_word[-1]

first_half_of_word_as_string = "".join(first_half_of_word) second_half_of_word_as_string = "".join(second_half_of_word) last_letter_as_string = "".join(last_letter)

convert_to_lowercase = first_half_of_word_as_string.lower() convert_to_uppercase = second_half_of_word_as_string.upper() convert_to_uppercase_final = last_letter_as_string.upper()

full_word = convert_to_lowercase + convert_to_uppercase + convert_to_uppercase_final

print(full_word)

sillycase.py
input_word = input("Type in a word:")

def sillycase(input_word):
    for x in input_word:
    return input_word

get_length = len(input_word)
word_length = int(get_length)
half_of_word = word_length//2
first_half_of_word = input_word[0:half_of_word]
second_half_of_word = input_word[half_of_word:-1]
last_letter = input_word[-1]

first_half_of_word_as_string = "".join(first_half_of_word)
second_half_of_word_as_string = "".join(second_half_of_word)
last_letter_as_string = "".join(last_letter)

convert_to_lowercase = first_half_of_word_as_string.lower()
convert_to_uppercase = second_half_of_word_as_string.upper()
convert_to_uppercase_final = last_letter_as_string.upper()

full_word = convert_to_lowercase + convert_to_uppercase + convert_to_uppercase_final

print(full_word)

1 Answer

Dave Harker
PLUS
Dave Harker
Courses Plus Student 15,510 Points

Hi lilysu3,

I'm just going to put this out there for you.

def sillycase(word):
    # get word midpoint for slice index with floor division operator - saves doing calulation twice
    midpoint = len(word)//2

    # create first half of 'new' word - word slice converted to lowercase
    first_half = word[:midpoint].lower()

    # create second half of 'new' word - word slice converted to uppercase
    second_half = word[midpoint:].upper()

    # return 'new' sillycase word by using string concatenation to join two word halves
    return first_half + second_half

If you wanted to make it brief you could try something like:

def sillycase(word):
    return word[:len(word)//2].lower() + word[len(word)//2:].upper()

But it's not as easy to understand or nice to read for that matter!

Keep at it, and happy coding!
Dave :dizzy: