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

Aamir Mirza
Aamir Mirza
25,077 Points

Sillycase - conflicting instructions

Hi,

In the comments inside the code, the code challenge tells us to split the first half of the word into lower case, and the second half into uppercase. The example it gives is Treehouse, which turns into treeHOUSE, splitting the odd-number-lengthed word in favour of the second half.

However, when you submit your code, it says it expects the string "Kenneth", to turn into "kennETH", splitting in favour of the first half (as opposed to the second half like treeHOUSE). This was a simple fix for me, but you might want to change the instructions to say that "Treehouse" should turn into "TreehOUSE" instead of "TreeHOUSE". :)

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(streng):
  half = int(len(streng)/2)
  first_half = streng[:half].lower()
  second_half = streng[half:].upper()
  streng = first_half + second_half
  return streng

3 Answers

Boris Ivan Barreto
Boris Ivan Barreto
6,838 Points

Hello Aamir,

The comments on the exercise says: # The first half of the string, rounded with round(), should be lowercased.

So you have to use the round() instead int()

def sillycase(item):
  half  = round(len(item)/2)
  return (item[:half ].lower()) + (item[half :].upper())
Aamir Mirza
Aamir Mirza
25,077 Points

Doh! Don't know how but I completely missed that. That would definitely make the code pass properly. However, the original instructions are still incorrect - since if you passed in "Treehouse" for item, it would return "treehOUSE" (item[:5] and item[5:]) instead of "treeHOUSE" as the code challenge instructions say,

Boris Ivan Barreto
Boris Ivan Barreto
6,838 Points

I have just run the code in the workspace and this is what I got: Treehouse Result: treeHOUSE

It definitely works as in the instructions

Ryan Burton
Ryan Burton
14,334 Points

I ended up doing all the steps in 1 giant line

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