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

Please can you help me with this python challenge

This challenge says where is sillycase() as an error message. please can someone tell me what's wrong.

# 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 (Treehouse):
  leng = (len(Treehouse) / 2)
  first = silly[:leng].round()
  second = silly[leng:]()
  return first + second

2 Answers

Hi Andy,

That's a really good attempt! You understand the general solution. We just need to fix some syntax and relocate the round() function.

First, let's tackle round(). Without it, when calling len() on a string with an odd number of letters, it will return a floating point value.

len("apple") / 2

# equals 2.5

# In order to round this value, we can put this expression
# inside the round function.

round(len("apple") / 2)

# equals 2

# Your variable is called leng, but really it's holding half the length.
# Perhaps consider renaming it to half.

Next up is slicing the string. Your code is trying to slice a string inside a undefined variable silly. Your method is accepting a variable called Treehouse, so you can either change the variable name being sliced to Treehouse or change the parameter of the method to silly - either way will work.

Finally, change the first half of the string to lowercase and the last half to uppercase.

"apple".upper()  # equals "APPLE"
"TOMATO".lower()  # equals "tomato"

# we can chain methods after slicing like this

# the string inside the variable name Treehouse will be sliced from index 0
# up to but excluding index half and then lowercased.

Hope this helps,


Hi thankyou for the good feedback and help. It passed I did it a bit different I just needed the round function in the leng variable.