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

silly.py

Not sure how to proceed

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(string):
  string_length = len(string)
  half_string = string_length / 2
  first_half = string[:half_string]
  result = first_half.extend(string[half_string:])
  return result

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

You are very close. A few corrections to you code. extend() works on lists but not on strings.

def sillycase(string):
  string_length = len(string)
  # need to round when length is odd
  half_string = round(string_length / 2)
  first_half = string[:half_string]
  # lower first half and upper second half 
  result = first_half.lower() + string[half_string:].upper()
  return result

Thanks Chris! After struggling through splitting up the first_half and second_half I totally forgot to .lower() the first half and .upper() the second half. Haha

I was also wondering about issues that would arise from input(string) with an odd number of elements. So, "round()" will takes care of this?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Yes. By default round() rounds to the nearest integer. 3.5 becomes 4, etc.