I don't know if anyone can help me with something strange that happens to me, it turns out that I am doing a simple mathematical operation, and then I am validating its result, if said result is less than 1 I want to print it on the screen, otherwise I would not do anything; but when executing I observe that when printing the result (coberturaCuota ) and its value is numeric without problems, but when passing it through the conditional it takes it as zero, which causes me a logical error and I do not understand why it assigns that value and ends the if as if it were less than 1, which should not happen if the value of hedgingQuota is greater than 0
for row in pcorte:
if row[4] == 1009:
x = row[0]
for row2 in aval: #consulta CPA
if x == row2[0]:
baseAd115.append(itemgetter(0,1,4,6,19)(row) + itemgetter(0,1,2,3,4,6)(row2))
for row in baseAd115:
if row[10] in empleados:
cuotaCobertura = int(0)
ingresos = row[6]
gastos = row[7]
cuota = row[4]
coberturaCuota = ((ingresos - gastos) // cuota) #Empleados: (Ingresos - gastos) / cuota
print(row[0],"Valor variable coberturaCuota antes del if ",coberturaCuota)
if coberturaCuota < 1:
print(row[0],"Valor variable coberturaCuota despues del if ",cuotaCobertura)
res1 = (row[0],row[1],observ,accion)
res.append(res1)
if row[10] in independientes:
cuotaCobertura = int(0)
utilNeta = row[8]
ingresos = row[6]
gastos = row[7]
cuota = row[4]
coberturaCuota = (((ingresos + utilNeta) - gastos)//cuota) #Independientes: (utilidad_neta - gastos) / cuota
print(row[0],"Valor variable coberturaCuota antes del if ",coberturaCuota)
if cuotaCobertura < 1:
print(row[0],"Valor variable coberturaCuota despues del if ",cuotaCobertura)
res1 = (row[0],row[1],observ,accion)
res.append(res1)
return(Base_adherencia(res))
220002393896 Valor variable coberturaCuota antes del if 5.0
220006718729 Valor variable coberturaCuota antes del if 3.0
220006718729 Valor variable coberturaCuota despues del if 0
220006718750 Valor variable coberturaCuota antes del if 7.0
220006718750 Valor variable coberturaCuota despues del if 0
220007719899 Valor variable coberturaCuota antes del if 2.0
220007719899 Valor variable coberturaCuota despues del if 0
220007768266 Valor variable coberturaCuota antes del if 2.0
220007768266 Valor variable coberturaCuota despues del if 0
The problem in your code is that you are comparing in the if variable quotaCoverage when the result of the operation was stored in the variable coverCuota .
Later, when you print inside the if, the text says that it is the value of coverageQuota , when in fact you print QuotaCobertura .
I don't know if you intended them to be the same variable. In that case, it is important to remember that they must have the exact same name, including capital letters, because python is case sensitive , that is, it is case sensitive.
In case you want to be different variables, I recommend that you put descriptive names (that speak about the variable and its objective or content) and different ones (so that they do not mix with others, as in this case).
It is good to always keep in mind good practices for naming elements , as well as naming conventions . If you are looking for some comprehensive guide to making code more verbose and readable, I strongly recommend applying pep8 .
Happy coding!