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 (Retired) Tuples Stringcases

reza sajadian
reza sajadian
718 Points

a tuple of lowered, uppered, titlecased, and reversed string

Hi. my code doesnt seem like working in this century. I need some help please.

def split(string): string_list = string.split() return string_list

def uppercased(string_split): uppered = string_split.upper() return uppered

def lowercased(string_split): lower = string_split.lower() return lower

def titlecased(string_split): titlecased = string_list.title() return titlecased

def reverse(string_split): reverse = string_split[::-1] return reverse

def stringcases(string): a = uppercased() b = lowercased() c = titlecased() d = reverse() tuple(a, b, c, d) return (a, b, c, d)

stringcases.py
# Handy functions:
# .upper() - uppercases a string
# .lower() - lowercases a string
# .title() - titlecases a string
# There is no function to reverse a string.
# Maybe you can do it with a slice?
def split(string):
  string_list = string.split()
  return string_list

def uppercased(string_split):
  uppered = string_split.upper()
  return uppered

def lowercased(string_split):
  lower = string_split.lower()
  return lower

def titlecased(string_split):
  titlecased = string_list.title()
  return titlecased

def reverse(string_split):
  reverse = string_split[::-1]
  return reverse

def stringcases(string):
  a = uppercased()
  b = lowercased()
  c = titlecased()
  d = reverse()
  tuple(a, b, c, d)
  return (a, b, c, d)

3 Answers

You're not passing the string to a,b,c,d

def split(string):
  string_list = string.split()
  return string_list

def uppercased(string_split):
  uppered = string_split.upper()
  return uppered

def lowercased(string_split):
  lower = string_split.lower()
  return lower

def titlecased(string_split):
  titlecased = string_list.title()
  return titlecased

def reverse(string_split):
  reverse = string_split[::-1]
  return reverse

def stringcases(string):
  a = uppercased(string)
  b = lowercased(string)
  c = titlecased(string)
  d = reverse(string)
  return (a, b, c, d)

You don't need the parenthesis at the last return, but I would agree with the answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

In addition to not passing the string argument to the function calls in stringcases(), as mentioned by Emily, there is a syntax error in titlecased().

Traceback (most recent call last):
  File "<string>", line 32, in <module>
  File "<string>", line 28, in stringcases
  File "<string>", line 14, in titlecased
NameError: global name 'string_list' is not defined

"string_list" should be replaced with the defined parameter "string_split"

def titlecased(string_split):
  titlecased = string_split.title()  # <-- fixed
  return titlecased
reza sajadian
reza sajadian
718 Points

Thank you all. Helpful.

Someone should close this thread Chris Freeman

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Hi Tomas, not sure what you mean by 'close'? Perhaps you meant mark as Best Answer? Threads are always open for further comments and posts including after being marked Best Answer.