It Doesn't Add Up!

Rami Chowdhury rami.chowdhury at gmail.com
Mon Oct 12 20:38:27 CEST 2009


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...




More information about the Python-list mailing list