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

hello, any ideas if the below code is not accepted as a correct answer? it seems to work as requested in "workspaces".

def sillycase(string): l = len(string) p=0 for i in string: if p < int(l/2): string[p] = string[p].lower() p +=1 else: string[p] = string[p].upper() p +=1 string = "".join(string) return string

sillycase.py
def sillycase(string):
    l = len(string)
    p=0
    for i in string:
        if p < int(l/2):
            string[p] = string[p].lower()
            p +=1
        else:
            string[p] = string[p].upper()
            p +=1
    string = "".join(string)
    return string

2 Answers

Steven Parker
Steven Parker
229,644 Points

Are you sure this works in the workspace? In Python, strings are immutable, so it's not possible to change an individual character inside a string (as on lines 6 and 9). It also wouldn't work to "join" a string.

Are you perhaps missing a line of code that converted the string into a list?

you are absolutely right.... i have the following code in workspaces. i think i add it to the function, it should work :)

many thanks!!!! it was very frustrating.

str = input ("what is your string? ")

string=list(str)

p= sillycase(string)

print(p)

Steven Parker
Steven Parker
229,644 Points

The list conversion needs to be done inside the function. Only the function code is needed (or used) in the challenge.