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

Collections (tuples)

The quiz challenge is: 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.

My function, when tried, in workspaces returns a tuple with the different string formats but I'm still not getting through with the quiz challenge.

Please help.

Thank you.

stringcases.py
def stringcases(str):
    wow = str[-1::-1]
    print ("{}" "," "{}" "," "{}" "," "{}".format((str.upper()), (str.lower()), (str.title()), (wow)))

1 Answer

Hello Idris! So the question is asking you to return a tuple. Your code, unfortunately, is printing the values, not adding them to a tuple. You can try something like this:

def stringcases(string):
  return (string.upper(), string.lower(), string.title(), string[::-1])

When you return values separated by a comma, you will ultimately return a tuple containing those values. Hope that helps!

JD Villa, thank you for that quick hint. I sometimes get confused with requirements of the questions. I thought I was required to use the format keyword in returning the values. I was almost there but I obviously lost my way. Thank you for your help on this. Cheers.