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 trialcompetent- fellow
5,846 PointsBlocked on Tuples: Stringcases
I am blocked on the tuples: Strincases code challenge. I use the following (perhaps overly complex) code to get all the cases:
def stringcases(string): upper = string.upper() lower = string.lower() titlecased = string.capitalize() str_reversed = reverse(string) return (upper, lower, titlecased, str_reversed)
def reverse(string): str_list = list(string) str_reversed = [] for letter in str_list: str_reversed.insert(0, letter) string = ''.join(str_reversed) return stringdef stringcases(string): upper = string.upper() lower = string.lower() titlecased = string.capitalize() str_reversed = reverse(string) return (upper, lower, titlecased, str_reversed)
"tomatoes" returns ('TOMATOES', 'tomatoes', 'Tomatoes', 'seotamot'), which I think is correct. But I get a "Bummer: Got the strong string for" [blank] message.
Maybe a bug?
Thanks in advance for your help!
def stringcases(string):
upper = string.upper()
lower = string.lower()
titlecased = string.capitalize()
str_reversed = reverse(string)
return (upper, lower, titlecased, str_reversed)
def reverse(string):
str_list = list(string)
str_reversed = []
for letter in str_list:
str_reversed.insert(0, letter)
string = ''.join(str_reversed)
return string
1 Answer
anthony pizarro
1,983 Pointsdef stringcases(string):
first = string.upper()
second = string.lower()
third = string.title()
forth = string[::-1]
return first, second, third, forth
or
def stringcases(string):
return (string.upper(), string.lower(), string.title(), string[::-1])
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsPro tip: If you encase your code blocks in ```python and ``` (leaving a blank line outside the makers before and after, you will get nicely colorized code. The ` is typically found left of the 1 key
def stringcases(string): return (string.upper(), string.lower(), string.title(), string[::-1])
becomes