Created
October 16, 2012 21:24
-
-
Save sweded/3902143 to your computer and use it in GitHub Desktop.
As an exercise, write a function that takes a string as an argument and outputs the letters backward, one per line.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fruit = "banana" | |
def revFruit(fruit): | |
index = len(fruit)-1 | |
while index >= 0: | |
letter = fruit[index] | |
print letter | |
index = index - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://pythontutor.com/visualize.html#code=fruit+%3D+%22banana%22%0A%0Adef+revFruit(fruit)%3A%0A%09index+%3D+len(fruit)-1%0A%09while+index+%3E%3D+0%3A%0A%09%09letter+%3D+fruit%5Bindex%5D%0A%09%09print+letter%0A%09%09index+%3D+index+-+1%0A++++++++%0ArevFruit(fruit)%0A&mode=display&cumulative=false&py=2&curInstr=28