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 trialabdou sbaa
Courses Plus Student 561 Pointscouldn't sole sillycase challenge , please help !
please tell me what's wrong with my code and give me some advices please , I know one letter variable name isn't good, but I got lazy after trying too many times ,I'm waiting for your answers
# 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(st):
c=int(len(st)/2)+1
a=st[:c]
a.lower
d=int(len(st)/2)+1
b=st[d:]
b.upper
st=a+b
return st
1 Answer
Kaleena Perkins
14,792 PointsHi there, So i noticed a couple things. The first is that usually when Treehouse mentions a certain method, such as round(), it means they usually want you to use it to complete the challenge. Currently the way you have it set up, it is returning "Treeh" as the first half, which isn't what you want. Also, in your code, you're calling upper and lower without parenthesis after them, so it's not actually calling those methods, which is why it seems to be returning the exact same word that you pass into the function.
A handy trick when you're having trouble is to add a print statement after each line to see what is happening in the code as it runs.
Below is a solution for this challenge. I've added comments before each line, explaining (hopefully) what is happening in each line of code. I hope that helps!
Take care, Kaleena
def sillycase(word):
# Create a new empty string to return
new_word = ""
# Find the length of the wrord
length = len(word)
# Find the first half by dividing the length in half, use round to
# round the number, and then the int() method to turn the float into an int
first_half = int(round(length /2))
# Make the new word equal to the first half of word, using slicing,
# and use the .lower to make it lowercase
new_word = (word[:first_half]).lower()
# Do the same for the last half of the word, this time making it upper
# case and using the += to concatenate with the first half that's already stored in new_word
new_word += (word[first_half:]).upper()
# return the new_word
return new_word
abdou sbaa
Courses Plus Student 561 Pointsabdou sbaa
Courses Plus Student 561 Pointsthank you for your help , I appreciate it :)
Kaleena Perkins
14,792 PointsKaleena Perkins
14,792 PointsNo problem Abdou! If you vote my answer "best answer," it would really help me out. Take care!
:)