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 trialMIkhail Vinogradov
2,669 Pointshello, 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
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
231,236 PointsAre 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?
MIkhail Vinogradov
2,669 Pointsyou 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
231,236 PointsThe list conversion needs to be done inside the function. Only the function code is needed (or used) in the challenge.