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 trialJonathan Shedd
1,921 PointsWhat is wrong with this function that makes a string lowercase in the first half and uppercase in the second half?
I'm not quite sure what I'm doing wrong with this particular challenge. Does it have something to do with the round function? Or is it the "len(str)/2" part of the code? It keeps returning the exception that slice indexes must be integers. All help is appreciated! :)
# 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(string):
return(string[0:round(len(string)/2, 0)].lower() + string[round(len(string)/2, 0):].upper())
1 Answer
Cindy Lea
Courses Plus Student 6,497 PointsYour return string is different from mine:
def sillycase(string):
midpoint = round(len(string)/2)
return string[:midpoint].lower() + string[midpoint:].upper()
Jonathan Shedd
1,921 PointsJonathan Shedd
1,921 PointsThanks, I got it now!