Last active
February 19, 2021 05:05
-
-
Save faizsiddiqui/b3163e05f21a2d288d637d484ed173f2 to your computer and use it in GitHub Desktop.
Basic Tax Calculation (IN)
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/python3 | |
def cal_taxable_income(income, deductions, regime): | |
taxable_income = income | |
if regime == 'old': | |
taxable_income -= deductions | |
return taxable_income | |
def income_tax_calculator(income, deductions, rules, regime): | |
taxable_income = cal_taxable_income(income, deductions, regime) | |
print(f'{"*" * 5}\tIncome\t\t: {income}\t{"*" * 5}') | |
print(f'{"*" * 5}\tDeductions\t: {deductions}\t{"*" * 5}') | |
print(f'{"*" * 5}\tTaxable\t\t: {taxable_income}\t{"*" * 5}') | |
_tax = 0 | |
for _key, rule in rules.items(): | |
if taxable_income <= rule["start"]: break | |
if taxable_income <= rule["end"]: | |
rule["end"] = taxable_income | |
print(f'\n{"*" * 5} Rule {_key + 1} : Start = {rule["start"]} | End = {rule["end"]} | Tax = {rule["tax"] * 100}% {"*" * 5}') | |
_tax += ((rule["end"] - rule["start"]) * rule["tax"]) | |
print(f'{"*" * 5}\tTax : {_tax}') | |
net_income = taxable_income - _tax | |
if regime == 'old': | |
net_income += deductions | |
print(f'\n{"*" * 8}\tNet Income : {net_income}\t{"*" * 5}') | |
print(f'{"*" * 8}\tTotal Tax : {_tax}\t{"*" * 5}') | |
income = float(input('Enter total yearly income : ')) | |
deductions = float(input('Enter total yearly deduction : ')) | |
## Rules ## | |
slab_rules_19_20 = { | |
0: { | |
'start': 0, | |
'end': 250000, | |
'tax': 0 | |
}, | |
1: { | |
'start': 250000, | |
'end': 500000, | |
'tax': 0.05 | |
}, | |
2: { | |
'start': 500000, | |
'end': 1000000, | |
'tax': 0.20 | |
}, | |
3: { | |
'start': 1000000, | |
'end': cal_taxable_income(income, deductions, 'old'), | |
'tax': 0.30 | |
} | |
} | |
## Rules ## | |
slab_rules_20_21 = { | |
0: { | |
'start': 0, | |
'end': 500000, | |
'tax': 0 | |
}, | |
1: { | |
'start': 500000, | |
'end': 750000, | |
'tax': 0.10 | |
}, | |
2: { | |
'start': 750000, | |
'end': 1000000, | |
'tax': 0.15 | |
}, | |
3: { | |
'start': 1000000, | |
'end': 1250000, | |
'tax': 0.20 | |
}, | |
4: { | |
'start': 1250000, | |
'end': 1500000, | |
'tax': 0.25 | |
}, | |
5: { | |
'start': 1500000, | |
'end': cal_taxable_income(income, deductions, 'new'), | |
'tax': 0.30 | |
} | |
} | |
print(f'\n{"*" * 10} Old Regime {"*" * 10}') | |
income_tax_calculator(income, deductions, slab_rules_19_20, 'old') # Old Regime | |
print(f'\n{"*" * 10} New Regime {"*" * 10}') | |
income_tax_calculator(income, deductions, slab_rules_20_21, 'new') # No deduction available in New Regime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment