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 trialKevin Ryu
1,286 PointsWhy 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.
- All upper
- All lower
- First letter titled
- string reversed
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
231,248 PointsIt 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
1,286 PointsFigured it out! Found .title().