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 trialWajid Mohammed
5,698 PointsNeed help on Stringcases program. Computer says Bummer! got the wrong string(s)
When I run the program in workspace it returns a tuple of all types of string required but program calls me Bummer and doesn't like what I wrote. Could you please help?
def stringcases(string_value):
upcase_string = string_value.upper()
lowcase_string = string_value.lower()
titlecase_string = string_value.capitalize()
reverse_string = ''
x = list(enumerate(string_value))
x.reverse()
for item in x:
reverse_string = reverse_string + item[1]
return upcase_string, lowcase_string, titlecase_string, reverse_string
3 Answers
Wade Williams
24,476 PointsThe reason your program isn't working is because string_value.capitalize() only capitalizes the first letter of the first word in a string, so you fail the Title cased condition. For title case use string_value.title().
This should work for you:
def stringcases(string_value):
upcase_string = string_value.upper()
lowcase_string = string_value.lower()
# title() used to capitalize every word of a string
titlecase_string = string_value.title()
# simplified way to reverse a string in python
reverse_string = string_value[::-1]
return upcase_string, lowcase_string, titlecase_string, reverse_string
Jeff Muday
Treehouse Moderator 28,722 PointsEverything in your code works, but the 'Titlecased' (first letter of each word is capitalized) needs to use the .title() string method. This will allow you to pass the challenge.
Capitalize only does the first word in a sentence. Where Title does the first letter of every word in the string.
x = 'the chicken laid eggs'
print x.capitalize()
'The chicken laid eggs'
print x.title()
'The Chicken Laid Eggs'
Wajid Mohammed
5,698 PointsThank you guys for spotting the issue.