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 trialEmil Hejlesen
3,014 Pointsstringcases.py
i dont know why this doesnt work
def stringcases(string):
return ((string.upper(),), (string.lower(),), (string.capitalize(),), (string[::-1]),)
2 Answers
Dave Harker
Courses Plus Student 15,510 PointsHi Emil Hejlesen,
Really close. The challenge requires that you title case the string for the third element of the returned tuple, you've capitalized it - You'll need to use .title() not .capitalize()
Also, I'm not sure why you've added the additional ,), around each element ... you're effectively returning a tuple containing single element tuples (kinda!) ... instead just try:
return string.upper(), string.lower(), string.capitalize(), string[::-1]
If you really want to separate the elements, you could use:
return (string.upper()), (string.lower()), (string.capitalize()), (string[::-1])
# or hardcore/my eyes are burning mode
return ((string.upper()), (string.lower()), (string.capitalize()), (string[::-1]))
# but it isn't necessary and I think makes it harder to read
Great effort though keep up the good work and happy coding,
Dave
Adam N
70,280 Points(('HI THERE',), ('hi there',), ('Hi there',), 'ereht ih')
^ that's some sample output i get with your function. Is that what the challenge wants from you?
Remember that an easy way to make something into a tuple is putting a comma after each item:
bob = 1, 2, 3, 4
# becomes (1, 2, 3, 4)
Emil Hejlesen
3,014 PointsEmil Hejlesen
3,014 Pointshi dave
it was the .capitalize() that was wrong, i changed it to .title() and the thing with the () was just to try and structure it for me but i didn't help, thank you for the help :)
Dave Harker
Courses Plus Student 15,510 PointsDave Harker
Courses Plus Student 15,510 PointsAnytime, glad you found it useful
Best of luck moving forward, and happy coding
Dave