Skip to content

Instantly share code, notes, and snippets.

@juanluisrto
Created July 12, 2023 10:08
Show Gist options
  • Save juanluisrto/f55e8e68e96570b735642914788bc561 to your computer and use it in GitHub Desktop.
Save juanluisrto/f55e8e68e96570b735642914788bc561 to your computer and use it in GitHub Desktop.
Función para estimar el irpf a pagar en España, teniendo en cuenta los tramos
def calculadora_impuestos(ingresos):
irpf_escalones = {
12_450 : 0.19,
20_200 : 0.24,
35_200 : 0.30,
60_000 : 0.37,
300_000 : 0.45,
1e100 : 0.47
}
tramos = sorted(irpf_escalones)
impuestos = 0
for t in tramos:
if t <= ingresos:
impuestos += t*irpf_escalones[t]
ingresos -= t
else:
impuestos += ingresos*irpf_escalones[t]
break
return impuestos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment