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 trialianmckellar
4,344 Pointsstuck on code challenge: sillyCase
Hey everyone!
So I've read the answer on other posts, and get it. But why doesn't this work?
# The first half of the string, rounded with round(), should be lowercased.
# The second half should be uppercased.
# E.g. "Treehouse" should come back as "treeHOUSE"
def sillycase(thing):
if half = round(len(thing) % 2):
lower_half = thing[0:half].lower()
upper_half = thing[half:].upper()
return thing[lower_half:upper_half]
1 Answer
Steven Parker
231,275 PointsThere are several issues, perhaps best explained with comments beside the code:
def sillycase(thing):
if half = round(len(thing) % 2): # this is an assignment, it doesn't need an "if" or ":"
# for half, you want to divide (/) not remaineder (%)
lower_half = thing[0:half].lower() # should not be indented, and you don't need 0 here
upper_half = thing[half:].upper() # also should not be indented
return thing[lower_half:upper_half] # you can't slice "thing" using the half-strings
# return lower_half + upper_half # but all you really need is to combine them