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 trialSean Flanagan
33,235 PointsWhat's wrong with this function?
Hi.
I've incorporated all the formats into my code as best I can. What am I doing wrong?
def stringcases(my_string):
return (my_string.upper(), my_string.lower(), my_string.capitalize(), my_string.reverse())
3 Answers
Mark Kastelic
8,147 PointsHi Sean,
You're close! Just replace the last element of your tuple with ''.join(reversed(my_string)) as I suggested:
def stringcases(my_string):
return (my_string.upper(), my_string.lower(), my_string.title(), ''.join(reversed(my_string)))
Note: I used two single quotes for the empty string, but you could also use "" as well.
Mark Kastelic
8,147 PointsSean,
The capitalize() function will only capitalize the first letter of the string. I believe you need to use the title() function instead which will capitalize the first letter of every word. For the string reversal you need to use: ''.join(reversed(my_string)). Note: that's an empty string (two single quotes with no space preceding the .join). Hope this helps.
Sean Flanagan
33,235 PointsHi Mark.
Thanks for your help. Here's what I came up with:
def stringcases(my_string):
return my_string.lower().upper().title().join(reversed(""))
When that didn't work, I tried:
def stringcases(my_string):
return (my_string.upper(), my_string.lower(), my_string.title(), my_string.join(reversed(""))
Sean Flanagan
33,235 PointsDone.
I've upvoted and given you Best Answer.
Thank you Mark!