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

oliverchou
oliverchou
20,886 Points

Can't get it right~

What's wrong with my code, and is the round() method necessary in this challenge? If so, how to use it?

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(s):
    middle = len(s)/2 + 1
    return s[:middle].lower() + s[middle:].upper()
Cheo R
Cheo R
37,150 Points

I redid it using round() and I got the output you are expected to have.

 s = 'Treehouse'
 middle = round(len(s)/2)
s[:middle].lower() + s[middle:].upper()
'treeHOUSE'

1 Answer

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

This should do it:

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

NOTE There was a lot of posts asking this question in the forum and took me like 2 secs to find the answer - the way of searching in the forum could save you some time and maybe some frustations :-)

oliverchou
oliverchou
20,886 Points

Thank you ~ I'll try it next time! :)