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 trialleocrudup
1,368 PointsI am getting error "slice indices must be integers or None or have_index_method.. Can someone help me figure out why?
I'm sure this has to do with my start stop and step in my slices so any help fixing this would be great.
# 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):
first_half = string[0:len(string) -1 / 2]
first_half.lower()
last_half = string[len(string)-1:len(string)/ 2 + 1: -1]
last_half.upper()
return first_half + last_half
2 Answers
Martin Cornejo Saavedra
18,132 PointsYou didn't round it, if you don't round, then the operation outputs a double, not an integer.
def sillycase(string):
index =
first_half = string[0: round(len(string) / 2)] #use round(), and don't use len() - 1 its not necessary
first_half.lower()
last_half = string[round(len(string) / 2) : len(string)]
last_half.upper()
return first_half + last_half
Jariel Arias
1,549 PointsBut in python doesn't any whole number divided by 2 give you a rounded whole number automatically? Every time I've tried it it has worked :/
Perry Stripling
20,210 PointsYes, Python automatically rounds answers with dividing. Odd numbers divided by 2, will give remainder, but will be rounded in the result. Looks like the problem is the -1.