Last active
May 21, 2020 12:56
-
-
Save ohr-emet/9fe341644f3e03026e565fef7c5c32ee to your computer and use it in GitHub Desktop.
py4e - Ch 6 Strings: Ex1 [print 'Banana' backwards]
This file contains hidden or 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
#Exercise 1: Write a while loop that starts at the last character in the string and works its way backwards to the first character in the string, printing each letter on a separate line, except backwards. | |
fruit = 'banana' | |
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