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

Kevin Ryu
Kevin Ryu
1,286 Points

Why doesn't this code work?

It works fine in my other editor. Goal is for the function to take the string, and return a tuple with 4 different string values.

  1. All upper
  2. All lower
  3. First letter titled
  4. string reversed
stringcases.py
def stringcases(string):
    title_string = ''
    reversed_string = ''
    for letters in string:
        if string.index(letters) == 0:
            title_string += letters.upper()
        else:
            title_string += letters.lower()
    tuple(title_string)
    a=-1
    for letters in string:
        reversed_string += string[a]
        a-=1
    tuple(reversed_string)

    return (string.upper(), string.lower(), title_string, reversed_string)

2 Answers

Steven Parker
Steven Parker
230,995 Points

It looks like your title method isn't doing quite what the instructions asked for. But you're also working too hard!

Similar to the first two values, the title case can be made with a built-in string method (you may need to look it up, but you might even guess the method name), and the final value can be made without a loop by using a slice.

Kevin Ryu
Kevin Ryu
1,286 Points

Figured it out! Found .title().