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 trialRobust Tran
2,802 PointsString cases function issue
""" Create a function named stringcases that takes a single string but returns a tuple of different string formats. The formats should be:
All uppercase
All lowercase
Titlecased (first letter is capitalized)
Reversed
There are str methods for all but the last one. """
I have no idea why I can't pass this challenge. I think I got the right answer but The Challenger keeping screaming at me "Bummer! Didn't get back all of the right cases"!?
Can someone help me out of it: (
def stringcases(something):
return str(something).upper(), str(something).lower(), str(something).capitalize(), something[::-1]
2 Answers
Alexander Davison
65,469 PointsYou are using the capitalize()
function when you should use the title()
function.
I think you can understand the difference between the two with a couple examples:
Pretend I'm in the Python Shell
>>> "alexander".capitalize()
"Alexander"
>>> "alexander".title()
"Alexander"
>>> "pizza is great".capitalize()
"Pizza is great"
>>> "pizza is great".title()
"Pizza Is Great"
As you see, captalize()
only capitalizes the very first letter in the string. title()
on the other hand capitalizes the first letter of every word in the string. The challenge wants you to use title()
.
I hope this helps
Happy coding!
~Alex
Robust Tran
2,802 PointsOh yes, It really was the key issue. Thank for your help. BTW: Some challenges description are a bit hard to understand. I would be nice that they have a small example about what is the expected result :)
I love Treehouse.
Alexander Davison
65,469 PointsI agree :)
Treehouse is wonderful! I feel like some of the code challenges (especially the Python Basic code challenges) have a little confusing description. But that's why you have other wonderful Treehouse students always willing to help!
Remember: This is real! We Treehouse students questions! Ask to your heart's content!
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsTagging Kenneth Love. I find this challenge very confusing, since the challenge says:
It should say something like:
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherUpdated the prompt. Thanks!