It Doesn't Add Up!

Victor Subervi victorsubervi at gmail.com
Mon Oct 12 20:43:18 CEST 2009


Ouch! You're right!
<;)
V

On Mon, Oct 12, 2009 at 1:38 PM, Rami Chowdhury <rami.chowdhury at gmail.com>wrote:

> On Mon, 12 Oct 2009 11:33:31 -0700, Victor Subervi <
> victorsubervi at gmail.com> wrote:
>
>  Hi;
>> I have the following code:
>>
>>    for row in data:
>>      i += 1
>>      total = 0
>>
>  [snip]
>
>> As you can see, the total doesn't accumulate! There are two rows. The
>> second
>> "Total 1:" should show "1.98", not 0! What gives?
>>
>
> You are setting total = 0 inside the for loop, so it is getting rebound for
> every row...
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091012/22e20245/attachment.html>


More information about the Python-list mailing list