Print a word, one character per line, backwards I have a problem that I solved in 2 different ways and I would like to know which one is better, cleaner and easier to read.
Problem:
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.
Example 1:
char = 'Wednesday'
cont = -1
cont2 = len(char)
cont3 = len(char) + 1
while cont &lt; cont2:
    print(char[cont2:cont3])
    cont2 = cont2 - 1
    cont3 = cont3 - 1

Example 2:
char = 'Wednesday'
cont = len(char) - 1
while cont &gt;= 0:
    cont2 = char[cont]
    print(cont2)
    cont -= 1
Looking at the two implementations side by side, ignoring the goal of the exercise and alternative implementations, I'd say the second example is better:

It uses one fewer variables.
It does a simple index lookup rather than a slice.
The implementation is easier to follow.

For simple problems like this it's often useful to think of the complexity of the solution as the number of &quot;tokens&quot;, or distinct language elements, necessary to write it down. For example, print(cont2) is four tokens: print, (, cont2 and ). By a quick read the first example has about twice as many tokens as the second.