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 trialMUZ140515 Herbert Chirwa
2,589 Pointscode asking where's string cases
l tried to return my_string.reverse but it recorded bummer where,s string_cases so l had to check previous presentations and came up with the highlighted code but still wont pass
# Handy functions:
# .upper() - uppercases a string
# .lower() - lowercases a string
# .title() - titlecases a string
# There is no function to reverse a string.
# Maybe you can do it with a slice?
def string_cases(my_string):
uppercase = tuple(list(my_string.upper()))
lowercase = tuple(list(my_string.lower()))
titlecase = tuple(list(my_string.title()))
revesrse = tuple(list(my_list.reverse()))
return (my_string.upper, my_string.lower, my_string.title, my_string[::-1])
1 Answer
Chris Freeman
Treehouse Moderator 68,457 PointsThe first issue might be the function name. I think it is asking for stringcases
(without the underscore).
Next to reverse a string you can use the slice notation. [:]
would mean to copy the whole string, [::1]
would mean to copy the whole string stepping one character at a time. [::-1]
would mean to copy the whole string one character at a time starting from the end.
I the code you've pasted, the extra tuple
and list
functions aren't needed:
def stringcases(my_string):
uppercase = my_string.upper()
lowercase = my_string.lower()
titlecase = my_string.title()
reverse = my_string[::-1]
return uppercase, lowercase, titlecase, reverse
MUZ140515 Herbert Chirwa
2,589 PointsMUZ140515 Herbert Chirwa
2,589 Pointsman you rock. i hadn't figure that had failed to figure out that you dont have to repeat the tuple when returning the string