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

Why is the str object not callable in this code

sillycase = list("sillycase")
second_half= sillycase[4:]
second_half = ''.join(second_half).upper()
second_half =list(second_half)
print second_half
del sillycase[4:]
sillycase[4:] = second_half
print ''.join(sillycase)

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

The code challenge requires you to write a function named sillycase, not make a variable with that name. The CC tries to call sillycase() and that's what's creating that error, since your sillycase is a string object and not a function.

Thanks Kenneth. I get it now.

Stephen Bone
Stephen Bone
12,359 Points

Hi Gerard

I've got to be honest and say I'm struggling to figure out your code (probably not aided by its formatting) so I'm going to talk through my solution and hope it helps.

Line 1 - First up you have to create a function which is achieved by using def followed by the name you want to give it and wrapping any argument(s) (if any) in parenthesis. So in this case it wants the function to be called sillycase and expects a string argument.

Line 2 - Next I got the length of the string using the len function, divided it by two to half it and then used the builtin round function as specified in the challenge.

Lines 3 & 4 - I declare a couple of variables and use string slicing to grab each half applying the lower and upper methods respectively.

Line 5 - And lastly I return the completed string using concatenation

def sillycase(abc):
  split = round(len(abc)/2)
  first = abc[:split].lower()
  second = abc[split:].upper()
  return first + second

Hope it helps!

Thanks that was very helpful.