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 trial

Python Python Collections (2016, retired 2019) Tuples Stringcases

Create 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
Steven Parker
230,250 Points

It 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. :wink:

Oh ok, thank you :) I will find that :) have a great day and thanks for your time.

Yeah man :) I appreciate you ... the title method was a bit tricky, but I found that in 5 minutes :)

2,470 Points

How 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
Steven Parker
230,250 Points

You'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! :+1: