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 trial

Python Python Collections (2016, retired 2019) Tuples Stringcases

Robust Tran
Robust Tran
2,802 Points

String 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: (

stringcases.py
def stringcases(something):
    return str(something).upper(), str(something).lower(), str(something).capitalize(), something[::-1]

2 Answers

You 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 :grin:

Happy coding! :tada:

:dizzy: ~Alex :dizzy:

Tagging Kenneth Love. I find this challenge very confusing, since the challenge says:

Titlecased (first letter is capitalized)

It should say something like:

Titlecased (first letter of every word is capitalized)

Robust Tran
Robust Tran
2,802 Points

Oh 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.

I 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! :smiley:

Remember: This is real! We Treehouse students :heart: questions! Ask to your heart's content! :grin: