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

John Fu
John Fu
2,594 Points

I ran my code through a work space and it seemed to work. What am I missing?

I'm trying to do the string cases exercise. I ran the code through my work space and it worked I think. I got the result that I wanted. But I keep receiving the bummer try again message. Is the issue that my tuple isn't properly created?

stringcases.py
def stringcases(string):
    uc = str.upper(string)
    lc = str.lower(string)
    titlec = str.title(string)
    reversec = (string[::-1])
    stringcase_tuple = (uc, lc, titlec, reversec)
    return (stringcase_tuple)

SPOILER ALERT, answer below but here is a hint

When you are stepping through the string via slice, you must consider the direction. The first to parameters are relevant to the direction you are headed.

1 Answer

SPOILER ALERT. See Comments for hint first.

def stringcases(string):
    uc = str.upper(string)
    lc = str.lower(string)
    titlec = str.title(string)
    reversec = (string[-1::-1]) # if slicing in reverse you will start with -1 instead of 0 which is implied
    stringcase_tuple = (uc, lc, titlec, reversec)
    return (stringcase_tuple)