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 (Retired) Slices sillyCase

Create a function, first half lowercased and last half uppercased.

Create a function named sillycase that takes a string and returns that string with the first half lowercased and the last half uppercased.

I'm not sure where i'm going wrong. Should I being using round and dividing it by two? Any input is much appreciated. Thank you

silly.py
# The first half of the string, rounded with round(), should be lowercased.
# The second half should be uppercased.
# E.g. "Treehouse" should come back as "treeHOUSE"
def sillycase(numbers):
lower = numbers[:3].lower()
upper = numbers[-2:].upper()
return lower + upper

1 Answer

andren
andren
28,558 Points

The problem with your function is that you are hardcoding the slice values, doing so makes it so that your function only works with words of a specific size. If I pass in your name "Rakshith" to the function for example I will get back "rakITH" which is obviously not the desired effect.

You need to figure out what half of the words length actually is, and then use that when slicing the word. Since the slice values have to be integers you will indeed have to use round if you divide the length of the string by two.

got it. thank you