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 trialBrent Liang
Courses Plus Student 2,944 PointsWhat's wrong with this code?
"Bash: command not found"
# 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
1 Answer
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsAnswering your question "What's wrong with this code":
- .lower() should be used as "string".lower() it can't be used with string's []
- You don't need +1.
- (Optional) PEP8 spacing recommendations.
- 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
BRIAN WEBER
21,570 PointsBRIAN WEBER
21,570 PointsYou 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: