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 (2016, retired 2019) Slices sillyCase

George Lugo
seal-mask
.a{fill-rule:evenodd;}techdegree
George Lugo
Python Web Development Techdegree Student 922 Points

whats wrong with my code

def sillycase(mystring): string = int(len(mystring / 2) string2 = int(len(mystring/ 2) return string.lower() + string2.upper()

sillycase.py
def sillycase(mystring):
    string = int(len(mystring / 2)
    string2 = int(len(mystring/ 2)
    return string.lower() + string2.upper()

2 Answers

def sillycase(string):
    middlePoint = int(len(string) / 2)
    firstHalf = string[:middlePoint]
    secondHalf = string[middlePoint:]
    return firstHalf.lower() + secondHalf.upper()

I'm getting the middle index of the string by taking the length of the string and dividing by 2, then converting the floating point value to an integer.

I'm getting the first and second halves of the string by using slices, then I'm returning the firstHalf lowercased joined together with the second half uppercased.

I hope this helps. ~Alex

George Lugo
seal-mask
.a{fill-rule:evenodd;}techdegree
George Lugo
Python Web Development Techdegree Student 922 Points
def sillycase(string):
    Dot = int(len(string / 2)
    josh = string[:Dot]
    alison = string[Dot:]
    return josh.lower() + alison.upper()

why doesn't this code work?

You didn't close the parentheses for the len function.

Dot = int(len(string / 2)    # Syntax Error, you didn't close all the parens
Dot = int(len(string / 2))    # This should work