While organizing the Excel data, I have a question. The For Moon is really useful and good, but I'm having a lot of trouble coding because I don't understand it perfectly. The list of "history" is from 0 to 100, so I made it into a for moon.
The code is as follows.
for a in history:
a = int(a['price'])*float(a['qty'])
b = b+1
if (a > 49900) and (a < 50100):
ws.cell(row=b, column=3, value=int(a))
else:
list(a)
for c in a:
r = a + c
ws.cell(row=b, column=3, value=int(r))
Assume that the list 'history' has key values of 'price' and 'qty', and in the for statement
if (a > 490000) and (a <50100):
ws.cell(row=b, column=3, value=int(a))
The above conditions have been created. What I'm curious about here is that if you enter Excel in order from the list of 'history' and get a value lower than the above conditions, I want to print it out when the value is between 49900 and 50100 in one row.
But I wonder how I can remember the next value and add it together to print it out.
python python3
if (c > 49900) and (c < 50100):
ws.cell(row=b, column=3, value=int(c))
else:
sum = 0
sum = sum + c
b = b-1
if (sum > 49900) and (sum < 50100):
ws.cell(row=b, column=3, value=int(sum))
else:
continue
This is how it works.Ask a question and answer it alone
© 2025 OneMinuteCode. All rights reserved.