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

Please where am i getting it wrong? it worked fine on my ide but not here. please correct me...

Challenge Task 1 of 1

Create a function named stringcases that takes a single string but returns a tuple of different string formats. The formats should be: All uppercase All lowercase Titlecased (first letter of each word is capitalized) Reversed There are str methods for all but the last one.

stringcases.py
def stringcases(string_arg):
    to_upper = str(string_arg).upper()
    to_lower = str(string_arg).lower()
    to_tcase = str(string_arg)[:1].upper() + str(string_arg)[1:].lower()
    to_reverse = string_arg[::-1]
    all_to_topule = to_upper, to_lower, to_tcase, to_reverse
    return all_to_topule

3 Answers

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hi Gee Your code it's not accepted just because of to_tcase variable It capitalize just the first word You can loop trough the string and capitalize every word and rejoined ex.

to_tcase = ' '.join([item.capitalize() for item in string_arg.split()])

This will solve the problem. Also you don't need to use str() method for the argument, it's already a string I hope this will help you out Happy coding

FYI, you don't need to put str before everything since the argument is already a string. Also, the best way to handle the title case issue is

to_tcase = string_arg.title()

Thanks Fehér... neva saw that coming. i now know what to do...