Skip to content

Instantly share code, notes, and snippets.

@ohr-emet
Last active May 21, 2020 12:56
Show Gist options
  • Save ohr-emet/9fe341644f3e03026e565fef7c5c32ee to your computer and use it in GitHub Desktop.
Save ohr-emet/9fe341644f3e03026e565fef7c5c32ee to your computer and use it in GitHub Desktop.
py4e - Ch 6 Strings: Ex1 [print 'Banana' backwards]
#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