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 trialMarie Lu
179 PointsWhy won't my sillycase work?
It seems fine to me, weird....
def sillycase(string):
len(string) = string_length
int(string_length / 2) = string_middle
list(string)
first_half = string[:string_middle]
first = str.lower(''.join(first_half))
second_half = string[string_middle:]
second = str.upper(''.join(second_half))
new = first+second
return new
2 Answers
Ari Misha
19,323 PointsHiya Marie! First off, You cant do len(string) = string_length
, coz in programming , you're assigning a value to right sided of assignment operator. Secondly, i cant read your code it all. Remember you need to make your code readable for other programmers as well. But i did pick this up that you're not doing "integer division", which denoted as "//". Integer division not only does a division for ya, it rounds the value as well. So this is how your code should look like:
def sillycase(words):
halves = len(words)//2
return words[:halves].lower() + words[halves:].upper()
Ari Misha
19,323 PointsWhen i say readable, i mean refactoring your code and following guidelines to write elegant and readable for human sets of eyes. Writing clean and elegant codes is itself an art. I mean yeah i wont expect any beginners to master right away but you can always practice. And compare your code with mine, you code took like 12 lines and mine took 3. So try to reduce the amount of lines.
This is an excellent guide to write elegant ad sexy codes.
Marie Lu
179 PointsMarie Lu
179 PointsBy making it readable do you mean adding comments or just simplifying overall? I think the simplifying might take me some time as I start working on projects I'll start figuring out what I'm doing unnecessary (hope I'm right in that logic :) )