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 trialAndy Davis
19,682 PointsProblem Uppercasing String
I don't know why using .upper() isn't uppercasing the string here. Any advice is much 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(str):
length = len(str)
return str[:length].lower() + str[:-length].upper()
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsI see three errors:
- The string dividing point should be in the middle. You are using the full
length
. Remember to divide by 2 and useround()
in case the length is odd - Both halves of your return are counting from the beginning of the string. A string can be divided using:
string[:mid] + string[mid:]
- Do not use the names of built-in functions for variable names. Replace
str
withstring
, or other name.
Andy Davis
19,682 PointsAndy Davis
19,682 PointsThanks so much Chris! Fwiw, here's how I ended up solving it: