Advertisement
karlakmkj

Practice - reverse string

Feb 16th, 2021
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. '''
  2. Write a function called reverse that takes a string text and returns that string in reverse.
  3. You may not use reversed or [::-1] to help you with this.
  4. You may get a string containing special characters (for example, !, @, or #).
  5. '''
  6.  
  7. def reverse(text):
  8.   new_text = ""
  9.   for i in range(len(text), 0, -1): # start from the end of text and decrement the index
  10.     new_text = new_text + (text[i-1])
  11.   return new_text
  12.  
  13. print reverse("happy")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement