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 trialSamuel Andrei Daniel Goje
1,351 PointsIs this a bug or am I missing something?
The bummer says ( and I quote) :
" Where's the sillycase() function" - Treehouse Debugger , 6 December 2014 , 11:57 Romanian time( GMT + 2 i think)
# The first half of the string, rounded with round(), should be lowercased.
# The second half should be uppercased.
# E.g. "Treehouse" should come back as "treeHOUSE"
def sillycase( string ):
count = 0
for letters in string:
count = count + 1
first = count
first = first / 2
first = round(first)
wfrist = word[:first]
wfirst.lower()
last = count - first
wlast = word[last:]
wlast.upper()
string = wfirst + wlast
2 Answers
Jeremy Settlemyer
4,149 PointsSo looking at your code I noticed that you have a for loop that counts the letters in the string. There is an easier and faster way by using the len() function which will return that value.
The second thing that I saw was you have first = on three lines. which could easily be put on one line like this:
first = round(count / 2)
now for the part where I think I see that you are having your issue is with the .lower() and .upper() functions.
If you run the .upper() or .lower() function by itself it doesn't change the value of the string that you ran it on. In the code you provided you did not change the actual value of the wfirst or wlast. In order to change the value of the string you would need something like this:
string = string.lower()
I hope this helps.
Michael De Marre
14,198 PointsHello,
You have a few typos and you made statements without re-declaring variables, such as:
first = round(first)
wfrist = word[:first]
wfirst.lower()
You were also counting the middle letter in the string in both the "first", and "last" variables.
The main reason why you received that error message was that you didn't specify a return value for the function.
I passed the challenge by modifying your code to this:
def sillycase( string ):
count = 0
for letters in string:
count = count + 1
first = count
first = first / 2
first = round(first)
wfirst = string[:first]
wfirst = wfirst.lower()
last = (count - first) + 1
wlast = string[last:]
wlast = wlast.upper()
return wfirst + wlast
sillycase("Treehouse")