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

half of indexes

I know that one of the first steps is is to separate the indexes of whatever string is inputted into two halfs using indexes, but I can't think of a way to do this.

1 Answer

AJ Salmon
AJ Salmon
5,675 Points

Hi Andrew! You'll need to use len() to get the length of the string, and create a variable for that number // 2. You can use variable names when indexing an item, as long as that variable represents an integer. So, use that variable that is half of the length of whatever the string is and use it to lowercase and uppercase the string! Example of what I mean:

def half_of_the_string(string):
    num = len(string) // 2
    # // is the operand that returns a whole integer even when dividing an odd number by 2
    print(num)

half_of_the_string('apples')
3
half_of_the_string('Treehouse')
4
half_of_the_string('abcdefghijklmnopqrstuvwxyz')
13

With this knowledge, return the concatenation (+) of the first half of the string, lowercased, and the second half of the string, capitalized. Hope this helps, and happy coding!