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

Tupples

Hi everyone,

I'm sorry I have to bother you on Xmas day. I'm trying to breathe python as much as I can! Haha.

Please help with this code challenge. My code is attached.

When I did run it in workspaces it worked. I got the tupples for all the different cases of the string but the checker on the code challenge is giving me an error message: "Bummer! Got the wrong string(s) for: Uppercase, Reversed, Titlecase, Lowercase."

Awaiting your urgent response please.

Thank you.

stringcases.py
def stringcases(str):
    for char in enumerate(str.upper(), start=1):
        return ("{}: {}".format(*char))
    for char in enumerate(str.lower(), start=1):
        return ("{}: {}".format(*char))
    for char in enumerate(str.title(), start=1):
        return ("{}: {}".format(*char))
    give = str[-1::-1]
    for char in enumerate(give, start=1):
        return ("{}: {}".format(*char))

I have also tried this:

def stringcases(str):
    index = 1
    wow = str[-1::-1]
    return ((index, str.upper()), "," , (index+1, str.lower()), "," , (index+2, str.title()), "," , (index+3, wow))

It also produced a tuple with different string formats but the checker still gives me an error message on the code challenge.

Awaiting hints from someone please.

Thank you.

1 Answer

Philipp Räse
PLUS
Philipp Räse
Courses Plus Student 10,298 Points

Hello there,

I used this code below and it works as expected. I hope you already found a good solution by yourself.

Otherwise maybe this will help:

def stringcases(string):
    string_uppercase = string.upper() #str-Function for uppercase
    string_lowercase = string.lower() #str-Function for lowercase
    string_titlecase = string.title() #str-Function for first letter of each word capitalized
    string_list = list(string) #Make a list from my string to make it 'accessable'
    string_reversed = "".join(string_list[-1::-1]) #build a reversed string from my list of characters
    return (string_uppercase, string_lowercase, string_titlecase, string_reversed) #return the tuple