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

Brent Liang
PLUS
Brent Liang
Courses Plus Student 2,944 Points

What's wrong with this code?

"Bash: command not found"

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 (string_given):
    lower_case = string_given.lower[:int(round(0.5*len(string_given)))]
    upper_case = string_given.upper[int(round(0.5*len(string_given))+1):]
    result_string = lower_case + upper_case
    return result_string
BRIAN WEBER
BRIAN WEBER
21,570 Points

You need to call .lower() after you have sliced the string. Also, you have a space between your function name and the parentheses where you type the argument, and you don't need to convert your rounded number to an integer since the round function already does that for you. See the code below:

def silly_case(string_given):
    lower_case = string_given[:round(len(string_given)*0.5)].lower()
    upper_case = string_given[round(len(string_given)*0.5):].upper()
    result_string = lower_case + upper_case
    return result_string

1 Answer

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,822 Points

Answering your question "What's wrong with this code":

  1. .lower() should be used as "string".lower() it can't be used with string's []
  2. You don't need +1.
  3. (Optional) PEP8 spacing recommendations.
  4. All of the rest is right. Just move .lower() and .upper() to the end, remove +1, and it works!
def sillycase(string_given):
    lower_case = string_given[:int(round(0.5 * len(string_given)))].lower()
    upper_case = string_given[int(round(0.5 * len(string_given))):].upper()
    result_string = lower_case + upper_case
    return result_string