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 trialChristopher Shanor
Courses Plus Student 2,537 PointsSillyness 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?
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
Front End Web Development Techdegree Graduate 33,271 Pointsyour 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.
james south
Front End Web Development Techdegree Graduate 33,271 Pointsno, 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
45,831 PointsYeah, 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.
Christopher Shanor
Courses Plus Student 2,537 PointsChristopher Shanor
Courses Plus Student 2,537 PointsI don't understand. If the string I provided (Sillycase) is used, the
second_half
variable does pick up wherefirst_half
leaves off. Even if "Treehouse" is used as the string, it has the same number of letters as "Sillycase". The returned value issillYCASE
. 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.
Christopher Shanor
Courses Plus Student 2,537 PointsChristopher Shanor
Courses Plus Student 2,537 Points...But I did what you suggested and it worked. Thank you.