Last active
June 13, 2018 19:57
-
-
Save glegoux/ae65a6f50791a1a2a3aa5b9e94443649 to your computer and use it in GitHub Desktop.
[Python] Compute french taxes in euro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# Compute french taxes in euro. | |
# | |
# usage: | |
# python3 impot.py <yearly_gross_salary> | |
TAXE_SLICES = [(9710, 0.14), (26818, 0.30), (71898, 0.41), (152260, 0.45)] | |
def get_taxe_amounts_per_slice(): | |
global TAXE_SLICES | |
taxe_amounts_per_slice = [0] | |
for slice_index in range(len(TAXE_SLICES) - 1): | |
amount = TAXE_SLICES[slice_index + 1][0] - TAXE_SLICES[slice_index][0] | |
taxe_amount = amount * (TAXE_SLICES[slice_index][1]) | |
taxe_amounts_per_slice.append(taxe_amount) | |
return taxe_amounts_per_slice | |
def get_yearly_net_salary(yearly_net_salary): | |
return yearly_net_salary * (1 - 0.23) | |
def get_category(yearly_net_salary): | |
global TAXE_SLICES | |
num_category = 0 | |
for taxe_slice, _ in TAXE_SLICES: | |
if yearly_net_salary <= taxe_slice: | |
break | |
num_category += 1 | |
return num_category | |
def get_taxe_amount(yearly_net_salary): | |
global TAXE_SLICES | |
taxe_amount = 0 | |
taxe_amounts_per_slice = get_taxe_amounts_per_slice() | |
num_category = get_category(yearly_net_salary) | |
for category in range(num_category): | |
taxe_amount += taxe_amounts_per_slice[category] | |
amount = yearly_net_salary - TAXE_SLICES[num_category - 1][0] | |
taxe_amount += amount * TAXE_SLICES[num_category - 1][1] | |
return taxe_amount | |
def get_salary(yearly_net_salary, taxe_amount): | |
return yearly_net_salary - taxe_amount | |
def get_salary_per_month(yearly_salary): | |
return yearly_salary / 12 | |
if __name__ == "__main__": | |
import sys | |
args = sys.argv[1:] | |
yearly_gross_salary = int(args[0]) | |
print("yearly gross salary: {0:.2f}€".format(yearly_gross_salary)) | |
yearly_net_salary = get_yearly_net_salary(yearly_gross_salary) | |
print("yearly net salary: {0:.2f}€".format(yearly_net_salary)) | |
monthly_net_salary = get_salary_per_month(yearly_net_salary) | |
print("monthly net salary: {0:.2f}€".format(monthly_net_salary)) | |
taxe_amount = get_taxe_amount(yearly_net_salary) | |
print("taxe amount: {0:.2f}€".format(taxe_amount)) | |
yearly_salary = get_salary(yearly_net_salary, taxe_amount) | |
print("yearly salary: {0:.2f}€".format(yearly_salary)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment