Skip to content

Instantly share code, notes, and snippets.

@ilanbiala
Last active December 30, 2020 21:44
Show Gist options
  • Save ilanbiala/be99da9091d5d4a0990bfba94f86220b to your computer and use it in GitHub Desktop.
Save ilanbiala/be99da9091d5d4a0990bfba94f86220b to your computer and use it in GitHub Desktop.
Quick calculator for federal tax payments for single filers in tax year 2020
from typing import List
# Single filer tax brackets for 2020 - 2021
tax_bracket_rates = {
(0, 9875): 0.1,
(9876, 40125): 0.12,
(40126, 85525): 0.22,
(85526, 163300): 0.24,
(163301, 207350): 0.32,
(207351, 518400): 0.35,
(518401, float("inf")): 0.37,
}
def print_taxes_by_bracket(bracketed_tax_payments: List[float], income: float) -> None:
print("Taxes paid per bracket:")
for (bracket_lower, bracket_upper), tax_payment in zip(tax_bracket_rates.keys(), bracketed_tax_payments):
print(f"${bracket_lower} - ${bracket_upper}: ${tax_payment:.2f} paid.")
print(f"Total taxes paid: ${sum(bracketed_tax_payments):.2f} ({sum(bracketed_tax_payments) / income * 100:.2f}% of income)")
def federal_tax_calculator(income: float) -> float:
bracketed_tax_payments = [0.0] * len(tax_bracket_rates.keys())
for i, ((bracket_lower, bracket_upper), tax_rate) in enumerate(tax_bracket_rates.items()):
if income < bracket_lower:
break
income_in_bracket = min(income - bracket_lower, bracket_upper - bracket_lower)
bracketed_tax_payments[i] = income_in_bracket * tax_rate
return bracketed_tax_payments
print_taxes_by_bracket(federal_tax_calculator(50000), 50000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment