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

srikanth soma
srikanth soma
1,572 Points

slices

def sillycase(arg):
    lower_case = arg[:4].lower()
    upper_case = arg[-5:].upper()
    result = lower_case + upper_case
    return result

I printed output and I was able to get right output but still I'm unable to pass the test where am I doing wrong?

sillycase.py
def sillycase(arg):
    lower_case = arg[:4].lower()
    upper_case = arg[-5:].upper()
    result = lower_case + upper_case
    return result

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Yes, it does work with the example they mention: "Treehouse". But your code assumes that the string is 9 characters long. This should work for any string no matter the length.

If I were to send in "treehouse is awesome", I would expect to get back "treehouse IS AWESOME". But with your code, I get back "treeESOME", which is obviously not what we're after.

Try not hard-coding the values of the indexes and instead work out how you would mathematically express half of the length of the string you're being sent. There are some hints in the instructions regarding this.

Hope this helps! :sparkles:

srikanth soma
srikanth soma
1,572 Points

Thanks for the help :)