Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Slices sillyCase

Avik Chakraborty
Avik Chakraborty
6,621 Points

My function is not working.

def sillycase(word): return word[:int(len(word)/2)].lower() + word[-int(len(word)/2):].upper()

sillycase.py
def sillycase(word):
    return word[:int(len(word)/2)].lower() + word[-int(len(word)/2):].upper()

2 Answers

Afloarei Andrei
Afloarei Andrei
5,163 Points

typo error at "......+ word[-int....." remove the '-'

Avik Chakraborty
Avik Chakraborty
6,621 Points

i put it on purpose to make a negetive value. example --> [-2:0] for the last two elements

Afloarei Andrei
Afloarei Andrei
5,163 Points

you'r code works if a word can be break in exactly 2 peaces like 'word', but if you have a word like 'treehouse' and you do a len('treehouse') / 2 the result will be 4. so your code will print treeOUSE because [-4:] is telling python to print only the las 4 characters from 'treehouse' and [4:] is telling python to print all the characters from the 4th till the end.