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 trialJirka Michalik
11,573 PointsCreate a function named stringcases that takes a single string but returns a tuple of different string formats. The form
What is wrong with my solution? ... I am getting output, which they want :/
Can you help me please? I'll appreciate it.
def stringcases(string):
return (string.upper(),string.lower(),string.capitalize(),string[::-1])
5 Answers
Steven Parker
231,269 PointsIt looks like you are using the wrong string method.
For the third value, the challenge said to capitalize the "first letter of each word". But the "capitalize" method only affects the first letter of the first word.
You might want to check the documentation on string methods. I'll bet you can find another method that will do what you want.
Jirka Michalik
11,573 PointsOh ok, thank you :) I will find that :) have a great day and thanks for your time.
Jirka Michalik
11,573 PointsYeah man :) I appreciate you ... the title method was a bit tricky, but I found that in 5 minutes :)
SUVODEEP DUBEY
2,470 PointsHow come this is wrong:
def stringcases(str1): str_upper= str1.upper() str_lower=str1.lower() str_titled=str1.title() temp=[] str_list=str1.split(" ") str_reverse_list = str.join(["{} ".format(str_list[-(i+1)]) for i in range(len(str_list))]) tupple_string_list = (str_upper, str_lower, str_titled, str_reverse_list) print(tupple_string_list)
stringcases("abcd efghijk lmnopqr stuvwxyz")
answer: ('ABCD EFGHIJK LMNOPQR STUVWXYZ', 'abcd efghijk lmnopqr stuvwxyz', 'Abcd Efghijk Lmnopqr Stuvwxyz', 'stuvwxyz lmnopqr efghijk abcd ')
This is what is asked in the question. Can anyone verify this code, I will appreciate it.
Steven Parker
231,269 PointsYou're working too hard! The challenge doesn't ask you to reverse the order of the words in the string, just reverse the entire string. This can be done in a single statement using a slice.
But good job on implementing a much more complicated process!
SUVODEEP DUBEY
2,470 PointsThanks Steven :)