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

jang walia
jang walia
7,717 Points

getting error while its running on other file

my silly case task is getting error.while i am running it successfully in my python file def sillycase(string): new_list=list(string) first_half=new_list[:len(new_list)//2] first_half[:]=["".join(first_half[:])] first_string="".join(first_half) second_half=new_list[-len(new_list)//2:] second_half[:]=["".join(second_half[:])] second_string="".join(second_half) capital=second_string.upper() complete=first_string+capital return complete

sillycase.py
def sillycase(string):
    new_list=list(string)
    first_half=new_list[:len(new_list)//2]
    first_half[:]=["".join(first_half[:])]
    first_string="".join(first_half)
    second_half=new_list[-len(new_list)//2:]
    second_half[:]=["".join(second_half[:])]
    second_string="".join(second_half)
    capital=second_string.upper()
    complete=first_string+capital
    return complete

1 Answer

Susan krystof
PLUS
Susan krystof
Courses Plus Student 2,662 Points

Why don't you just make it easy like this.

def sillycase(arg):
    result =[]     #create an empty list
    div = len(arg)//2    #set the value for half of length of the argument
    result.extend([(arg[:div]).lower(), (arg[div:]).upper()])    #slice and extend
    return "".join(result)    #return a joined list