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 trialDavid Kiesel-Nield
3,756 PointsError asks where stringcases() is though I have it defined.
When I check my work, I get the error "Bummer! Where's 'stringcases()'?"
I have stringcases(word) defined and that error goes away when I remove 'word' from my definition, but there is no way to have a function act on an argument if it doesn't accept arguments. Is there something I'm missing here?
This code works as expected when tested in the workspace, so I'm at a loss as to what I need to be doing differently. Is there a chance there's a mistake in the challenge?
# 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 stringcases(word):
up = word.upper()
low = word.lower()
titl = word.title()
rev = word[::-1]
return(up, low, title, rev)
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsThe error seems to be in the line:
def stringcases(word):
up = word.upper()
low = word.lower()
titl = word.title() #<-- Typo "titl" instead of "title"
rev = word[::-1]
return(up, low, title, rev) #<-- "title" not defined due to typo
With "title" undefined, the function doesn't load, therefore is not found.
Abdillah Hasny
Courses Plus Student 3,886 Pointsare this way more efficient ?
def stringcases(data):
return(data.upper(),data.lower(),data.title(),data[::-1])
Chris Freeman
Treehouse Moderator 68,441 PointsIt is more efficient to not create interim variables. During the earlier lessons function it helps to have these variables for debug and exploration.
To check the efficiency, I ran both the corrected OP solution and your solution 5 times in loops of 1,000,000 executions each. Time is in seconds:
DK:
4.039442306999263
4.326730489000511
3.417532984999525
3.450944000999698
3.3833166990007157
AB:
3.2500369149993276
3.2893079640007272
3.2199465869998676
3.4106744480004636
3.3793593910004347
So unless you're running this code a lot, the difference is negligible
Maxwell Hunter
Python Web Development Techdegree Graduate 29,640 PointsCheck the name of the variable there, it looks like you put 'titl' instead of 'title'
David Kiesel-Nield
3,756 PointsDavid Kiesel-Nield
3,756 PointsI reloaded the challenge and tried again and was successful.