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 trialAJ Salmon
5,675 PointsStringcases
It says that my function isn't returning the correct string(s). When I run it in my terminal, it returns:
>>> stringcases('apple')
('APPLE', 'apple', 'Apple', 'elppa')
>>>
I thought this was the desired tuple. I appreciate any insight as to what the challenge actually wants me to return!
def stringcases(string):
uppercase = string.upper()
lowercase = string.lower()
titlecase = string[:1].upper() + string[1:].lower()
reverse = string[::-1]
tup = (uppercase, lowercase, titlecase, reverse)
return tup
2 Answers
andren
28,558 PointsThe issue is the title case. Title casing is where each letter in a sentence is capitalized, like the style you'd use on titles of documents and the like. Your code only capitalizes the first letter in the string, which is not enough if the string contains multiple words.
Python actually has a method for title casing strings just like it has for uppercasing and lowercasing them. So you can solve this task by simply using the title
method on the third string.
Like this:
def stringcases(string):
uppercase = string.upper()
lowercase = string.lower()
titlecase = string.title()
reverse = string[::-1]
tup = (uppercase, lowercase, titlecase, reverse)
return tup
Wesley Trayer
13,812 PointsI think it's because the challenge wants you to use .title().
titlecase = string.title()
Other than that I don't see anything wrong with your code.
Good idea using slices to uppercase the first letter. :)
Wesley Trayer
13,812 PointsOops! It didn't tell me somebody else had posted while I was answering.