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 trial

Python Python Collections (Retired) Slices sillyCase

Andy Davis
Andy Davis
19,682 Points

Problem Uppercasing String

I don't know why using .upper() isn't uppercasing the string here. Any advice is much appreciated.

silly.py
# 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
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

I see three errors:

  • The string dividing point should be in the middle. You are using the full length. Remember to divide by 2 and use round() 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 with string, or other name.
Andy Davis
Andy Davis
19,682 Points

Thanks so much Chris! Fwiw, here's how I ended up solving it:

def sillycase(string):
  length = round(len(string)/2)
  return string[:length].lower() + string[length:].upper()