In Python, the simplest way to reverse a Sequence
is with a slice:
>>> string="abc!de@fg"
>>> print(string[::-1])
gf@ed!cba
Slicing will give you a copy of the sequence in reverse order.
In general, you want a function to do one thing. Returning a value and printing some output are separate concerns, so they should not be conflated in the same function. If you have a function that returns a reversed string, you can simply print the function:
print(reverse("abc"))
Then, you can see that your actual algorithm is fine, if not entirely Pythonic:
def reverse(text):
l=len(text)
output = ""
while ((l-1)!=0):
output += (str(text[l-1]))
l=l-1
output +=(str(text[0]))
return output
You can clearly see now that it's the print function in your way.