Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Write a function called reverse that takes a string text and returns that string in reverse.
- You may not use reversed or [::-1] to help you with this.
- You may get a string containing special characters (for example, !, @, or #).
- '''
- def reverse(text):
- new_text = ""
- for i in range(len(text), 0, -1): # start from the end of text and decrement the index
- new_text = new_text + (text[i-1])
- return new_text
- print reverse("happy")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement