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!

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

What is wrong with my code (works in shell but not in test)

When I run in shell stringcases('what is Wrong with my code') I get ('WHAT IS WRONG WITH MY CODE', 'what is wrong with my code', 'What is wrong with my code', 'edoc ym htiw gnorW si tahw') but I have error in test

def stringcases(s):
    return s.upper(), s.lower(), s.upper()[0] + s.lower()[1:], ''.join(list(s)[::-1])

2 Answers

28,552 Points

The problem is with the title case. The challenge instructions does not make it super clear but title case is actually a case system where every word in the sentence has it's first letter capitalized (like you'd see in a book title) not just the first word.

And there is actually a built-in method for making a string title cased which is simply called title.

Also while not directly wrong I would like to point out that your string reversal code is needlessly complex. A string is considered a type of list in python and can be sliced on it's own.

Taking both of those things into account you end up with this code:

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

Which will pass the challenge.

james south
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

iirc on this one they want upper, lower, every word capitalized, and every even index backwards. so your first two are ok, for the third one, there's a capitalize method and a title method, check title out. on the last one, you are reversing the string but i think they want only even indices, so slice or otherwise remove the odd indices from the string. edit - this is not the one where they want only even indices, your 4th one is ok to reverse the string.

Works. 4th should be a simple s[::-1] (no extra list-join steps) and 3rd s.title()