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 trialBrandon Evans
8,154 PointsIs this sort of code frowned upon?
I solved the solution like this:
def sillycase(str):
str.split()
return str[:(len(str) // 2)].lower() + str[(len(str) // 2):(len(str))].upper()
This honestly looks a little confusing to me at first glance, although from a programmatic standpoint, I figured this was a little bit more efficient than maybe some other approaches. I do not have much experience in DRY or efficient coding so I was just curious if this is something acceptable in the real world or if this is just too confusing and not practical.
Thanks! :)
2 Answers
Steven Parker
231,269 PointsLearning how to make your code more DRY will come with experience, but here's two hints:
- the "str.split()" line doesn't do anything and can be omitted
- the second slice doesn't need a "stop" value
ERDAL DINCER
1,635 Pointssillycase=['Treehouse'] len=len(sillycase) sillycase=sillycase.upper(0:(len/2+1)+sillycase.lower(len/2::)
What is wrong with mine?
Steven Parker
231,269 PointsWithout formatting it's hard to read, but some issues that I think I'm seeing are:
- the "def" line is missing to begin a function
- the name "sillycase" seems to be used for both the function name and for a variable
- the name "len" which is a built-in function seems to also be used as a variable
- it looks like slices are being attempted using parentheses instead of brackets
Start a fresh question if you need more help. You should always do that instead of posting one as an "answer".
Brandon Evans
8,154 PointsBrandon Evans
8,154 PointsAh, I see! That makes perfect sense too. Sweet, thank you for the pointers, Steven!