Steve Holden wrote:
> john boy wrote:
>
>> using the following program:
>>
>> fruit = "banana"
>> index = 0
>> while index < len (fruit):
>> letter = fruit[index-1]
>> print letter
>> index= index -1
>>
>> this program is supposed to spell "banana" backwards and in a vertical
>
john boy wrote:
[top-posting corrected]
>
> Steve Holden <[EMAIL PROTECTED]> wrote:john boy wrote:
>
>>using the following program:
>>
>>fruit = "banana"
>>index = 0
>>while index < len (fruit):
>>letter = fruit[index-1]
>>print letter
>>index= index -1
>>
>>this program is supposed to spell "ban
Craig Marshall wrote:
> Or, if you're *really* just trying to reverse the string, then the
> following might read more easily (although it's probably longer):
> fruit = list(fruit)
> fruit.reverse()
> fruit = ''.join(fruit)
same thing, on one line:
fruit = "".join(reversed(fruit))
same thi
Steve Holden wrote:
> Note, however, that there are more pythonic ways to perform this task.
> You might try:
>
> for index in range(len(fruit)):
> letter = fruit[-index-1]
> print letter
>
> as one example. I'm sure other readers will have their own ways to do
> this, many of them more elegan
> Note, however, that there are more pythonic ways to perform this task.
> You might try:
>
> for index in range(len(fruit)):
>letter = fruit[-index-1]
>print letter
Or, if you're *really* just trying to reverse the string, then the
following might read more easily (although it's probably
"john boy" <[EMAIL PROTECTED]> wrote:
> using the following program:
>
> fruit = "banana"
> index = 0
> while index < len (fruit):
> letter = fruit[index-1]
> print letter
> index= index -1
> after spelling "banana" it gives an error message:
> refering to line 4: letter = fruit[in
john boy wrote:
> using the following program:
>
> fruit = "banana"
> index = 0
> while index < len (fruit):
> letter = fruit[index-1]
> print letter
> index= index -1
>
> this program is supposed to spell "banana" backwards and in a vertical
> patern...it does thisbut after
using the following program:
fruit = "banana"
index = 0
while index < len (fruit):
letter = fruit[index-1]
print letter
index= index -1
this program is supposed to spell "banana" backwards and in a vertical patern...it does thisbut after spelling "banana" it gives an error me