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

Evgeny Shilov
Evgeny Shilov
21,283 Points

Exercise: "Bummer! Didn't get back all of the right cases"

Can't find my mistake. Could somebody help pls?

stringcases.py
def stringcases(some_string):
    some_tuple = ()

    upper_string = some_string.upper()
    lower_string = some_string.lower()
    capitalized_string = some_string.capitalize()
    reversed_string = some_string[-1::-1]

    some_tuple = (upper_string, lower_string, capitalized_string, reversed_string)
    print(some_tuple)
    return some_tuple

1 Answer

  1. To reverse a string, you should add [::-1] in front of it, not [-1::-1].
  2. The challenge was expecting you to use the .title() function, not the .capitalize() function. They do different things (title capitalizes the first letter on every word while capitalize just capitalizes the very first one).
  3. Why are you printing the tuple?

In order to fix this, you have to fix the above:

def stringcases(string):
    uppercased = string.upper()
    lowercased = string.lower()
    titled = string.title()
    reversed = string[::-1]

    return uppercased, lowercased, titled, reversed

I hope you understand :)

~Alex

Evgeny Shilov
Evgeny Shilov
21,283 Points

Alex, you are the best! Lightning fast response. Thank you

  1. Yes, it finally clicked for me how this slice works
  2. Was not clear for me from the description
  3. Was trying to debug it locally

It's not wrong to use string[-1::-1] to reverse the string but it's not necessary to specify the start to be -1

Oh, I didn't know XP

Thanks for responding

Alex, thanks for your clarification on title vs capitalize. I didn't see the difference until I did a string with multiple words