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

Regarding the Sillycase challenge in the Python Collections lesson.

My python code evaluated successfully inside of Workspaces before I realized that the challenge requires you to use the .round() method to slice out the first 4 and last 4 indexes in an iterable and return it in a new list. I have not the foggiest idea of how to approach this challenge using the .round() method. Any pokes in the right direction would be much appreciated.

Here is the code that evaluated successfully in Workspaces:

'''python

my_list = "Treehouse"

def sillycase(itr): first = itr[:int(len(itr)/2)] last = itr[int(len(itr)/2):len(itr)]

firstLow = str(first) lastUp = str(last)

new_list = firstLow.lower() + lastUp.upper()

print(new_list)

sillycase(my_list) '''

silly.py
def sillycase(itr):
  first = itr[:int(len(itr)/2)]
  last = itr[int(len(itr)/2):len(itr)]

  firstLow = str(first)
  lastUp = str(last)

  new_list = firstUP.lower() + lastUp.upper()

  return new_list

The example code I pasted does not show up with the appropriate line spacing but I think you get the picture.

2 Answers

Here's how I did it:

def sillycase(my_string):
  rounded_index = round(len(my_string)/2)
  my_string = my_string[0:rounded_index].lower() + my_string[rounded_index:].upper()
  return my_string

Thanks, Bryan! While I was away I was able to pass the challenge with the following code:

def sillycase(itr):
  first = itr[:round(len(itr)/2)]
  last = itr[round(len(itr)/2):len(itr)]
  new_list = first.lower() + last.upper()
  return new_list

I like your approach, though. Well done!