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 trialJared Barr
1,911 PointsBummer: Got the wrong string(s) for:
prompt asks for:
""" 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. """
After searching for similar cases in the forum and testing on my own, I feel like I am getting the output needed regardless the type of string that is inputted but am getting the error
Bummer: Got the wrong string(s) for:
which no info on what is wrong with the string or what it is looking for.
Any Ideas?
(print was used for testing / verifying and is not necessary in code. )
def stringcases(single_string):
case_list = []
def uppercased(single_string):
uppercase_string = single_string.upper()
#print("UPPERcase: ", uppercase_string)
case_list.append(uppercase_string)
#print(case_list)
return uppercase_string
def lowercased(single_string):
lowercase_string = single_string.lower()
#print("lowerCASE: ", lowercase_string)
case_list.append(lowercase_string)
#print(case_list)
return single_string.lower()
def titlecased(single_string):
titlecase_string = single_string.capitalize()
#print("Titlecased: ", titlecase_string)
case_list.append(titlecase_string)
#print(case_list)
return single_string.capitalize()
def reverser(single_string):
reversed_string = single_string[::-1]
#print("resrever: ", reversed_string)
case_list.append(reversed_string)
#print(case_list)
return reversed_string
uppercased(single_string)
lowercased(single_string)
titlecased(single_string)
reverser(single_string)
print(case_list)
tuple_list = tuple(case_list)
print(type(tuple_list))
print(tuple_list)
return tuple_list
2 Answers
Steven Parker
231,236 PointsYou're working too hard! You can do this without nested functions inside the function. You won't need a list, and you can create a tuple by just listing items with commas in between as part of the "return" statement.
Also, you only need to define the function. You wont need to call it or "print" anything.
Jared Barr
1,911 PointsThanks again Steven Parker for your assistance. Life got in the way for a bit but I wanted to come back and post the solution I FINALLY got :)
"""
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.
"""
def stringcases(single_string):
def titlecase(single_string):
single_string = single_string.lower()
lower_list = single_string.split(",")
title_list = []
for x in lower_list:
x = x.title()
title_list.append(x)
title_string = ",".join(title_list)
return title_string
return single_string.upper(), single_string.lower(), titlecase(single_string), single_string[::-1]
Jared Barr
1,911 PointsJared Barr
1,911 PointsThanks for responding, Steven.
I realized that I didnt need to do all the functions w/in the function I was just kind of testing things out at the time and the 'prints' are there for my testing purposes. I'm still unclear as to why this is not working when it seems to output what is being requested in the prompt.
Am I misunderstanding you about this part?
It also seems to output what I am looking for, only i'm getting the same error.
edit: it seems the title case section at least is coming out incorrectly
Steven Parker
231,236 PointsSteven Parker
231,236 PointsYou're close, but for the third item the instructions ask for the "first letter of each word is capitalized". But the "capitalize" method sets the first letter of the whole string capital, but makes the entire remainder of the string (including the first letter of all other words) lower case. So you'll probably want to use a different string method.