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 trialAbdullah Jassim
4,551 PointsI understand its a single string, but shouldnt the for loop work for all cases? Suggestions to make this work?
def stringcases(single_string):
for item in (single_string):
return tuple(item.upper())
return tuple(item.lower())
return tuple(item.title())
return tuple(item[::-1])
def stringcases(single_string):
for item in (single_string):
return tuple(item.upper())
return tuple(item.lower())
return tuple(item.title())
return tuple(item[::-1])
1 Answer
Viraj Deshaval
4,874 PointsStrings are single thing and if you loop over it then it will loop over each letter. For example:
>>> string1 = "abcdefg hijklmn"
>>> for str1 in string1:
... print(str1)
...
a
b
c
d
e
f
g
h
i
j
k
l
m
n
You can see its looping over the string but it will give you each letter and not the single string.
Your need to modify your code so that it will return the string with tuple. Remove the for loop as it's not required and you need to only return the tuple. For example:
return (tuple1upper(), tuple2lower(), tuple3title(), tuple4reverse)
do something like this and you will definitely pass this challenge.