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 trialAlejandro Byrne
2,562 PointsI tried my code in workspaces and it worked perfectly. Why not in the challenge?
I copied and pasted my exact code from the console , that worked fine, but it says Try Again! in the error. Why?
def sillyCase():
string = input('>>')
if len(string) % 2 == 0:
half1 = round(len(string) / 2)
half2 = round(len(string) / 2)
else:
half1 = round((len(string) / 2))
half2 = round((len(string) / 2))
print(string[:half1].lower() + string[half2:].upper())
sillyCase()
2 Answers
Alexander Davison
65,469 PointsAs Chris said, you should return the new string and not print
ing it. Second, you seem to be getting user input, but the challenge didn't at all ask for that. Third, your function should take an argument and lowercase that string's first half then uppercase the second half. Finally, you don't need to call the function. Code challenges almost always call functions automatically for you, unless said that it wants you to call it manually.
Keep in mind that code challenges are extremely picky and if you do even one thing the challenge didn't like like for example catching user input for no reason, it won't let you pass. You shouldn't write any code unless the code is what the challenge wants you to! Also, you shouldn't over-think the challenge. Your code may work perfectly in Workspaces, but that doesn't always means that's what the challenge wants you to put into the challenge.
I hope this helps
~Alex
Chris Freeman
Treehouse Moderator 68,441 PointsYou've created a function. What does it return
?
Alejandro Byrne
2,562 PointsOh, dumb mistake. Switched print with return, and it worked. Hate it when I make mistakes like that. My brain just passed right through it... Anyway, I did that and made a few changes:
- Changed the name of the function to sillycase.
- Switched the input of string to the parameter of the function.
- Removed the call of the function at the end.
Thanks for the help - even though thee answers were right under my nose.
Alejandro Byrne
2,562 PointsAlejandro Byrne
2,562 PointsOh, dumb mistake. Switched print with return, and it worked. Hate it when I make mistakes like that. My brain just passed right through it... Anyway, I did that and made a few changes:
Thanks for the help - even though thee answers were right under my nose.
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsGood job
I didn't even notice that the
sillyCase
name is wrong. I'm used to camelCase, so I just thought that was okay at first glanceNice catch!