Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Slices sillyCase

Abdullah Jassim
Abdullah Jassim
4,551 Points

Why is this logic wrong?

def sillycase(string):
    half = int(len(string)//2)

    lower_cap = string[:half].lower()
    upper_cap = lower_cap[half:].upper()

    cap = upper_cap
    return cap

result = sillycase("treehouse")
print(result)

1 Answer

Steven Parker
Steven Parker
222,348 Points

You've got the right idea, but there's a few issues:

  • you need to use the original string to make both parts
  • you'll need to return the result of joining both parts together
  • "You'll want to use the int() function or integer division, //" — but you don't need both
  • you won't need to call the function, only define it
  • you won't need to print anything
Abdullah Jassim
Abdullah Jassim
4,551 Points

I thought the upper_cap includes the first answer, which is why I only printed the upper_cap. For e.g. -

variable = "Treehouse" lower_cap = treehouse uppercap = treeHOUSE

hence print just uppercap. Whats wrong with the logic??

Steven Parker
Steven Parker
222,348 Points

If you apply the 2nd slice to the first result, you'll get an empty string, since the first result is only "half" long.