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

Can anyone help me figure out whats wrong with my code to return uppercase, lowercase, titlecase, and reverse?

the method I have written works on my powershell not with the treehouse compiler. what I have to do is create a function that takes a string makes tuples of that string in uppercase, lowercase, titlecase and in reverse. Can't see what I've done wrong when my code works in powershell.

stringcases.py
def stringcases(a_string):
    upper = tuple([a_string.upper()])
    lower = tuple([a_string.lower()])
    title = tuple([a_string.title()])
    reverse = tuple([a_string[::-1]])
    return tuple([upper, lower, title, reverse])

3 Answers

There is no need to convert each individual string into a tuple

def stringcases(a_string):
    upper = a_string.upper()
    lower = a_string.lower()
    title = a_string.title()
    reverse = a_string[::-1]
    return upper, lower, title, reverse

Otherwise your code looks good

thanks a lot appreciate the help

Ahmed Khairi
Ahmed Khairi
2,113 Points

or you can do like this to make the code more pythonic:

def stringcases(a_string):
    return a_string.upper(),a_string.lower(), a_string.title(), a_string[::-1]