Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
def reverse(text):
word = ""
l = len(text) - 1
while l >= 0:
word = word + text[l]
l -= 1
return word


please help me to understand about this solution. what & how it was made?

What I have tried:

def reverse(text):
word = ""
l = len(text) - 1
while l >= 0:
word = word + text[l]
l -= 1
return word
Posted
Updated 16-Jul-18 21:22pm
Comments
Mehdi Gholam 17-Jul-18 3:17am    
Somebody thought and wrote the code in a text editor... try to ask question that make sense.

1 solution

It's pretty obvious: all it does is find out the length of the string, then append each character to the word starting from that the right end and working to the beginning.

Get a piece of paper and a pencil, and try following the instructions yourself - you'll soon see how it works.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900