Bummer! You must be logged in to access this page.

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

darcyprice
darcyprice
4,442 Points

What is the expected output?

What is the expected output for the objective?

Without spoiling the correct code, could someone please give me an example of what the expected output is for: stringcases('heLLo There').

Thank you, much appreciated!

On a (related) side note, perhaps it would be worthwhile to include example output as part of the objectives - as CodeWars does.

stringcases.py
def stringcases(txt):
    """
    (str) -> tuple

    From txt, return a tuple of different string formats:
    all uppercase, all lowercase, titlecasted, and reversed.

    >>> stringcases('heLLo There')
    ('HELLO THERE', 'hello there', 'Hello There', 'ereht olleh')
    """

    txt_list = []

    txt_list.append(txt.upper())

    txt_list.append(txt.lower())

    txt_list.append(txt.title())

    reverse_txt = ''

    len_count = 0
    index_count = -1

    while len_count < len(txt):
        reverse_txt += txt[index_count]
        len_count += 1
        index_count -= 1

    txt_list.append(reverse_list)

    print(tuple(txt_list)

3 Answers

Stuart Wright
Stuart Wright
41,120 Points

The example you've written in your docstring is correct:

('HELLO THERE', 'hello there', 'Hello There', 'ereht olleh')
darcyprice
darcyprice
4,442 Points

Thanks Stuart!

I am able to get the expected output with the above code, any idea why it's not passing?

Note, to reverse the txt, I have removed the while loop and using the far simpler: txt_list.append(txt[::-1])

Stuart Wright
Stuart Wright
41,120 Points

Is the problem simply that you are printing rather than returning your list of tuples? The rest looks good to me.

darcyprice
darcyprice
4,442 Points

Ah, how silly of me. Now works fine. Thanks again :)