Python Python Collections Tuples Stringcases

John Fu
John Fu
2,137 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)
Frank Genova
Frank Genova
Python Web Development Techdegree Student 12,586 Points

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

Frank Genova
Frank Genova
Python Web Development Techdegree Student 12,586 Points

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)