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 trialAshley Hu
5,799 PointsHey, its saying that slice indices must be integers. My code isnt working but it works on my text editor
This is my code def sillycase(string): return string[0:len(string)/2].lower() + string[(len(string)/2)::].upper()
# 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:len(string)/2].lower() + string[(len(string)/2)::].upper()
1 Answer
Peter Lawless
24,404 PointsTry using floor division for your slicing. The division operator returns a float, not an integer, so that is what is causing the error. Floor division will round the result down to the nearest integer. Try this:
def sillycase(string):
return string[:len(string)//2].lower() + string[(len(string)//2):].upper()
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsThe code comments mention using the
round()
function. Floor division works part of the time but it doesn't always return the same result as round()Either will produce the same result for the example string "Treehouse" but the challenge tests a different string and they don't produce the same result for that one.