-1
I have a var local
that for some reason is not being zeroed
print(pf,qcx) <------ essa linha é executada
qcx = 0 <------ essa não
i do not know debuggar in jupyter and do not understand why this variable is never zeroed
below is the summary of my code:
def names(resp = 'n'):
vprod,icms,desc,qtrib,nome,pf,x,utrib,bo,new,qcx,itens = 0,0,0,0,'',0,0,'',False,'',0,{}
for child in rooti.iter():
bo = False
try:
...
if bo:
if resp == 'n':
for i in utrib:
if i.isdigit():
new += i
else:
pass
qcx = int(new)
pf = (vprod + icms - desc)/(qcx * qtrib)
print(pf,qcx)
qcx = 0
else:
pf = (vprod + icms - desc)/qtrib
pv = '{:.2f}'.format(pf)
itens[nome]['preço'] = pv
if child.tag[36:] == 'total':
break
except ZeroDivisionError or IndexError or KeyError:
continue
def preco():
...
def init(resp='s'):
tree = ET.parse(xml)
rooti = tree.getroot()
names(resp)
preco()
newteste = ''
for i in teste:
newteste += str(i)
print(newteste)
print('='*58)
init()
resp = input('bateu? [S/N]')
if resp.lower() == 'n':
init('n')
print(newteste)
print('='*58)
output:
print(pf,qcx):
4.09 24
0.02410214168039539 2428
0.00024099362511736705 242828
2.5820713648285644e-06 24282830
2.589072170691088e-08 2428283024
4.632903120482823e-11 242828302415
4.632903120479961e-13 24282830241515
4.632903120479932e-15 2428283024151515
4.632903120479932e-17 242828302415151515
4.632903120479932e-19 24282830241515151515
4.632903120479932e-21 2428283024151515151515
4.6329031204799314e-23 242828302415151515151515
I didn’t stop to understand all the code, but anyway, before the
print
you doqcx = int(new)
, that is, the variableqcx
receives some value, you print, then changes the value to zero, but then you doqcx = int(new)
again, prints, switches to zero, etc... This means that theqcx = 0
becomes useless, because before printing you always change this value toint(new)
– hkotsubo
qcx serves inside a mathematical expression and must be reset as soon as it is executed. the problem is that qcx = 0 is not assigning 0.
– gbrdoidao
It is assigning yes, the problem is that in the following iteration you do
qcx = int(new)
before using the variable again (from what I understood from your code). Put aprint(qcx)
shortly afterqcx = 0
to confer– hkotsubo
got it, int(new) was not being. obg
– gbrdoidao