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 trialmarcolamoon
16,915 PointsTried everything i could think of...HELP!
Create a function called "reverse_text" that takes a string as an argument, and returns a string with those words reversed. So reverse_text("balloon") should return "noollab".
from django import template
register = template.Library()
def reverse_text(agr):
return template("noollab")
4 Answers
Carlton M Mandikiyana
7,836 Pointsdef reverse_text(string): return string[::-1]
this will pass the challenge
Steven Parker
231,248 PointsThe challenge is only telling you that reverse_text("balloon") should return "noollab" as an example.
You should not assume what actual argument will be given, and your function should create the output by using the argument and performing a process on it that will give the desired result.
marcolamoon
16,915 Pointsi did the following code and its not working.
from django import template
register = template.Library()
def reverse_text(balloon): return "noollab"
Steven Parker
231,248 PointsYou're still returning a fixed string that would only be the proper response if the function was called with "balloon" as an argument. But what if it was called with "widget" or "jabberwock?
You need to compute a reversed version of the argument so the answer will be correct no matter what the input is.
wisdom mapeka
25,213 Pointshow Did you solve this one, I am facing a similar challenge ,
Steven Parker
231,248 PointsThere are a few ways to do this, one would be to use the "reversed" option on a loop.
But a slice with a negative step value is even easier.
Munyaradzi D Sabamba
8,310 Pointsyou should return the answer as below
def reversed_text("balloon"): return balloon[::-1]
it should pass the test
Steven Parker
231,248 PointsThat's what I was hinting at a year and a half ago. I was just trying to avoid giving away a "spoiler".