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

Emilio Andere
Emilio Andere
495 Points

Could I get the answer?

It's really confusing and I want to move on

sillycase.py
def sillycase(string):
    string[:5].lowercased
    string[5:].uppercase

1 Answer

Steven Parker
Steven Parker
231,275 Points

Most of the hints I gave you last time can still be applied:

  • you won't know how long the string will be, so you can't used fixed values (like "5") in the slice
  • the names of the functions for changing case are ".lower()" and ".upper()"
  • you'll need to combine the two new parts together (perhaps put them on the same line with "+" between)
  • you'll need to "return" the combined result

If you want to move on without completing a challenge, just go back to the course index (using link at top left) and select the next step from there. I'll make it even easier in this particular case, the next step is Introduction to Dictionaries

But I recommend sticking with it, this is stuff you'll need to know as you move on.

Emilio Andere
Emilio Andere
495 Points

this is the only thing I don't understand.

-you won't know how long the string will be, so you can't use fixed values (like "5") in the slice

Steven Parker
Steven Parker
231,275 Points

What I mean is that instead of taking the first (or last ) 5 characters in the slice, you need to take half of the string. If you use 5 you are assuming that you know that the string will be 10 characters long.

But you don't know how long it will actually be, so you need to compute how much "half" is.