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

I need you to create a new function for me. This one will be named sillycase and it'll take a single string as an argum

HELP

sillycase.py
def sillycase("lovecoding"):
    first_half = lovecoding[0:5]
    second_half = lovecoding[5:]
    return first_half.lowercase + second_half.uppercase

1 Answer

Hi,

you need to create a function and pass an argument. The argument will be a string. You don't need to pass an actual your "custom" string because otherwise, your function is not going to work for any random string, it is not universal. The same for the indexes you used inside of the function. It won't work for the word "blah". Check out the syntax for the functions that convert the letter into the upper- and/or lowercase. And also in your code, you are passing the "lovecoding" as a string, but inside of the function, you are using it as a variable. This doesn't make any sense for the python, it just throws you an error, that lovecoding is undefined.

Try this, it passed the challenge. You can use fewer lines of code, though.

def sillycase(string):
    middle = len(string)//2
    first_part = string[0: middle].lower()
    second_part = string[middle:].upper()
    result = first_part + second_part
    return result