[Tutor] Program for outputing the letter backward
John Fouhy
john at fouhy.net
Wed Mar 29 08:10:02 CEST 2006
On 29/03/06, Hoffmann <oasf2004 at yahoo.com> wrote:
> Hi John,
>
> (1) vehicle[index] is: 'c'
> (2) If index = index = 1, so vehicle[index] becomes:
> 'a'
What I'm getting at here is that, by changing index, we can change
which letter we are looking at. And index is a number, which means
it's easier to reason about than letters are.
Let's have a look at a possible solution:
>>> vehicle = 'car'
>>> index = 2
>>> print vehicle[index]
r
>>> index = 1
>>> print vehicle[index]
a
>>> index = 0
>>> print vehicle[index]
c
Notice that the three print statements are identical. That suggests
we could write the code in a loop, with 'print vehicle[index]' in the
body of the loop. Can you have a go at that?
--
John.
More information about the Tutor
mailing list