Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Slices sillyCase

Christopher Shanor
PLUS
Christopher Shanor
Courses Plus Student 2,537 Points

Sillyness in Sillycase: Python Collections Challenge

Not sure why this code doesn't pass the challenge. I have tested in the console and I receive "sillYCASE".. any ideas?

sillycase.py
silly = "Sillycase"

def sillycase(silly):
    first_half = silly[:int(len(silly)/2)].lower()
    second_half = silly[4:].upper()
    return(first_half + second_half)

2 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,258 Points

your first half is responsive to various word lengths, but your second half arbitrarily starts at 4. so you just need to make them the same so that the second half picks up where the first half leaves off.

Christopher Shanor
Christopher Shanor
Courses Plus Student 2,537 Points

I don't understand. If the string I provided (Sillycase) is used, the second_half variable does pick up where first_half leaves off. Even if "Treehouse" is used as the string, it has the same number of letters as "Sillycase". The returned value is sillYCASE. I could see it failing if a different length string was used.

Granted, I didn't use // integer division, but didn't think it was required.

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,258 Points

no, floor division is not required, it's just an alternate way to end up with an integer. you should expect that the autograder is using a variety of unseen test cases on the code you submit, such that writing code that works on the examples they provide may not be sufficient to pass a given challenge. note that the challenge does not actually ask you to put a string into a variable, and that in any event giving a variable the same name as a subsequent function parameter does not create any relation between them. the code isn't being called with the variable as the argument. they ignored the silly = 'sillycase' line and ran your code with unseen test cases, which is why it must be responsive to words of different lengths.

Mark Miller
Mark Miller
45,831 Points

Yeah, James is right, we have to solve it for any case, not just for one example. It looks like an if-else problem exists. To route the letters to either the first or second half to receive lower() upper(). Actually, think it needs if-else inside of a for each loop, because there seems to be no other way to slice the second half, which is > than the first half. I'm trying list.index() inside of an if, inside of a for _ in list. I'm unable to pass this challenge.