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 trialDave Laffan
4,604 PointsStringcases - Can't see what I've done wrong?
Hey
My code below works, at least in the way I interpret the question, but I get the error
"Bummer! Didn't get back all of the right cases"
Looking at other questions on this, seems people are using slices and beacuse of that I can already see a better way of doing it, but don't know why this method isn't accepted?
Could someone please show me where it's wrong?
Thank you!
def stringcases(arg1):
my_list = []
my_list.append(arg1.upper())
my_list.append(arg1.lower())
my_list.append(arg1.capitalize())
backwards = []
for letter in arg1:
backwards.insert(0, letter)
reverse = ''.join(backwards)
my_list.append(reverse)
my_tuple = tuple(my_list)
return(my_tuple)
3 Answers
Alexander Davison
65,469 PointsYou are using the capitalize
function, however the challenge expected you to use the title
function.
I'm pretending that I'm in the Python Shell
>>> "abc".capitalize()
"Abc"
>>> "abc".title()
"Abc"
>>> # Over here you might be wondering the differences, to find out the differences just read on...
>>> "abc abc".capitalize()
"Abc abc"
>>> "abc abc".title()
"Abc Abc"
I hope this demonstrates the difference.
I hope this helps! ~Alex
By the way, you look like a great Python programmer so far! If you'd like a little challenge, check this out!
Dave Laffan
4,604 PointsYes, that makes sense now, thank you very much
Alexander Davison
65,469 PointsCan you provide a "Best Answer"? It helps with the Community filtering and it also gives a bonus 12 points to whoever receives the best answer :)
Thank you! ~Alex
Dave Laffan
4,604 PointsYes, of course, there you go
Alexander Davison
65,469 PointsThank you! Um... Nice smiley face emoji. :)