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

Nicholas Hobbs
Nicholas Hobbs
2,057 Points

Help with stringcases - error about right cases

Hi,

I have written some code to return the 4 cases, upper, lower, title, and reversed in python, tested in Python 3.6.0, checked the cases with the type() function embedded in the code and it seems to return what is being asked in the challenge, however I am getting "Bummer! - Didn't get back right cases1".

Please give me a hint as to what I have missed?

stringcases.py
def stringcases(single_string, *args):

    hi_ball = single_string.upper()
    all_list = []
    for thing in hi_ball:
        all_upper = ("{}".format(thing))
        all_list.append(all_upper)
    all_upper_tup = tuple(all_list)
    return(all_upper_tup)

    low_ball = single_string.lower()
    low_list = []
    for thing in low_ball:
        all_lower = ("{}".format(thing))
        low_list.append(all_lower)
    low_list_tup = tuple(low_list)
    return(low_list_tup)

    title_ball = single_string.title() 
    first_list = []
    for thing in title_ball.title():
        first_only = ("{}".format(thing))
        first_list.append(first_only)
    first_list_tup = tuple(first_list)
    return(first_list_tup)

    rev_ball = single_string[::-1]
    rev_list = []
    for thing in rev_ball:
        rev_only = ("{}".format(thing))
        rev_list.append(rev_only)
    rev_list_tup = tuple(rev_list)
    return(rev_list_tup)

2 Answers

I think you are over-thinking this challenge.

All you need to do is:

def stringcases(arg):
    lowered = arg.lower()
    uppered = arg.upper()
    titled = arg.title()
    reverse = arg[::-1]
    return (lowered, uppered, titled, reverse)

What I'm doing is I'm setting a variable called lowered to the lowercased version of the string, setting a variable called uppered to the uppercased version of the string, etc.

Finally, I return a tuple of all of those variables.

I hope this helps. If you got any more questions, please ask below :smile:

~Alex

Nicholas Hobbs
Nicholas Hobbs
2,057 Points

Hi Alex,

Thank you so much, wow that was so much simpler, I really really appreciate your help. Sometimes I go a bit down the wrong path and then try cut my own path which, as you know is counter productive.

Thank you for your time!

Best Regards,

Nick

Can you give a Best Answer? It helps with the Treehouse Community filtering. Thank you!

It also gives a bonus 12 forum points to whoever gained the best answer.

~alex

Nicholas Hobbs
Nicholas Hobbs
2,057 Points

Thanks Alex! that was a great answer. I really appreciate it helped me understand the use of args much better.