Login

Back

Traversing a string

A common task in programming is working your way through a string, both forwards and backwards.

Q1. Get this code working:

1.    def forwards(anyWord):
2.        index = 0
3.        while index < len(anyWord):
4.            letter = anyWord[index]
5.            print(letter)
6.            index = index + 1
7.
8.    myWord = input("Please enter a word or phrase >>> ")
9.
10.  print("\n")
11.
12.  forwards(myWord)

13.  input("\n\nPress any key to quit >>> ")

Q2. Describe how this code works.

Please register to read more ......