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
James White
6,159 PointsMore elegant way of writing sillycase()?
Here's my code:
def sillycase(string_theory):
first_half_length = round(len(string_theory) / 2)
second_half_length = len(string_theory) - first_half_length
first_half_string = string_theory[0:first_half_length]
first_half_string = first_half_string.lower()
second_half_string = string_theory[first_half_length:]
second_half_string = second_half_string.upper()
return first_half_string + second_half_string
print(sillycase("JODYwhite"))
3 Answers
Ryan Merritt
5,789 PointsMaybe something like...
def sillycase(my_string):
middle = round(len(my_string)/2)
two_halves = [my_string[:middle].upper(), my_string[middle:].lower()]
return ''.join(two_halves)
James White
6,159 PointsHeh. I didn't even notice I created a variable I wasn't using.
Nathan McElwain
4,575 PointsWhat about this?
def sillycase(a):
x = round(len(a)/2)
y = a[x:].upper()
z = a[:x].lower()
return z+y