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

Prisca Egbua
Prisca Egbua
1,167 Points

trying to return tuples of various string format, given a string

Please, what am I doing wrong? THANKS

stringcases.py
def stringcases(single_string):
    uppercase = single_string.upper()
    lowercase = single_string.lower()
    titlecase = single_string.title()
    reversal = single_string[-1::-1]
    upper = tuple(uppercase)
    lower = tuple(lowercase)
    title = tuple(titlecase)
    reverse = tuple(reversal)
return upper, lower, title, reverse

1 Answer

Kent Åsvang
Kent Åsvang
18,823 Points

tuple("string") return -> ("s", "t", "r", "i", "n", "g")

I'm guessing you want something like this -> (UPPERCASE, lowercase, Titlecase, esrever)

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

Hope I helped.

Prisca Egbua
Prisca Egbua
1,167 Points

Yeah, it works, thanks. But the question actually requested for tuple in different formats, am surprised this works.

Kent Åsvang
Kent Åsvang
18,823 Points

I'm not a paying student so I can't watch the challenge, but from what I could gather from you post the function was supposed to return a tuple of strings with different format. If that is the case then the function is just fine:)