<br clear="all">Chris<br>
<br><br><div class="gmail_quote">On Mon, Oct 12, 2009 at 11:33 AM, Victor Subervi <span dir="ltr"><<a href="mailto:victorsubervi@gmail.com">victorsubervi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi;<br>I have the following code:<br><br> for row in data:<br> i += 1<br> total = 0<br></blockquote><div><br></div><div>In the above line, you're setting total to 0 each time the loop runs.</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> quantity = form.getfirst('order_' + str(i), '')<br> if quantity != '':<br> sql = 'select * from products p join %s c on p.ID=c.ID where c.ID=%s;' % (client, str(i))<br>
cursor.execute(sql)<br> stuff = cursor.fetchone()<br> price = str(int(stuff[5]*100))<br> price = price[0:len(price)-2] + '.' + price[-2:]<br> item, price, description, discount = stuff[2], price, stuff[3], stuff[8]<br>
order += 'Item #: ' + item + '\tQuantity: ' + quantity + '\tPrice: ' + price + '\tDiscount: ' + str(discount) + '\tDescription: ' + description[:20] + '...<br />\n'<br>
print 'Total 1: %s<br />' % total<br> total += float(price) * int(quantity) * (100 - discount)/100<br> print 'Total 2: %s<br />' % total<br> order += 'TOTAL: $' + str(total)<br>
<br>It prints out the following to screen with the print statements:<br><br>Total 1: 0<br>
Total 2: 1.98<br>
Total 1: 0<br>
Total 2: 6.3<br><br>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?<br>TIA,<br><font color="#888888">Victor<br>
</font><br>--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
<br></blockquote></div><br>