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
Stivan Radev
1,475 PointssillyCASE
I need you to create a new function for me.
This one will be named sillycase and it'll take a single string as an argument.
sillycase should return the same string but the first half should be lowercased and the second half should be uppercased.
For example, with the string "Treehouse", sillycase would return "treeHOUSE".
Don't worry about rounding your halves, but remember that indexes should be integers. You'll want to use the int() function or integer division, //.
I'm curious on how people solved this challenge. So if you solved this challenge and want to share your code below that would be great because I want to see how people approached this challenge. I believe that it would improve my knowledge if I see how other people solved this problem.
Thanks!
====================>THE CODE BELOW WORKS FINE<===================
def sillycase(word):
lenghts = len(word)
quick_math = int(lenghts / 2)
answer_1 = word[:-quick_math]
answer_2 = word[quick_math:]
return answer_1.lower() + answer_2.upper()
2 Answers
Alexander Davison
65,469 PointsMy solution:
def sillycase(string):
midway = (len(string) // 2) + 1
return string[:midway].lower() + string[midway:].upper()
Steven Parker
243,656 PointsThe code above has a stray hyphen on the line where "answer_1" is assigned, making the stop value negative. Remove that hyphen and it will pass the challenge.
And my solution was similar to Alex's except I didn't add one (does it actually work that way?):
def sillycase(word):
half = len(word) // 2
return word[:half].lower() + word[half:].upper()
Stivan Radev
1,475 PointsStivan Radev
1,475 PointsPS: I went back and tested it out and it ended up not working????? But the first time it worked !!!! ?!? !? !?!?!? Confused.