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

Nathaniel Bell
Nathaniel Bell
6,020 Points

My sillycase.py solution works in the shell but is not accepted by the challenge...can someone help me understand why?

This snippet works with all of the test strings I've thrown at it in the shell, but the challenge is just not accepting it...can someone help me identify what I've done wrong here? Thanks!

sillycase.py
def sillycase(word):
    return (word[:(len(word)//2)]) + (word[(len(word)//2):].upper())
Nathaniel Bell
Nathaniel Bell
6,020 Points

I've re-worked it using an additional line, and it appears to now return the requested output, but still won't pass the challenge...I'm kinda stumped:

def sillycase(word):
    half = round(len(word)/2)
    return word[:half] + word[half:].upper()

1 Answer

James J. McCombie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
James J. McCombie
Python Web Development Techdegree Graduate 21,199 Points

Hello,

had a quick look at the challenge.

your function will return the string 'TreeHOUSE', using the example given.

you would need to make that first character lowercase before you return it, perhaps do this first in the function?

Also the challenge states 'don't worry about rounding your halves' perhaps you will also fail if the tests they are using detect a call to round, but see if you pass with the first modification before worrying about that.

Nathaniel Bell
Nathaniel Bell
6,020 Points

Hi James, thanks for your input!

I figured it out - I wasn't converting the first half to lowercase at all, so if an uppercase letter was provided in the first half the results check failed. I added .lower() to the first part of the expression in the return statement and passed the check.

Thanks a lot for checking it out! (Here's what worked in the end:)

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