Paycheck Calculator
Calculate your net take-home pay after federal tax, FICA, state tax, and pre-tax deductions.
PaycheckCalculator.disclaimer
Часто задаваемые вопросы
Реализация кода
def calculate_paycheck(
gross_annual: float,
filing_status: str = "single",
state_tax_rate: float = 0.05,
k401_pct: float = 0.06,
health_ins: float = 200,
hsa: float = 50,
pay_periods: int = 26
) -> dict:
gross = gross_annual / pay_periods
pretax_deductions = gross * k401_pct + health_ins + hsa
# 2024 federal tax brackets (single)
brackets_single = [
(11600, 0.10), (44725, 0.12), (95375, 0.22),
(201050, 0.24), (383900, 0.32), (487450, 0.35), (float('inf'), 0.37)
]
brackets_married = [
(23200, 0.10), (89450, 0.12), (190750, 0.22),
(364200, 0.24), (462500, 0.32), (693750, 0.35), (float('inf'), 0.37)
]
brackets = brackets_married if filing_status == "married" else brackets_single
taxable_annual = gross_annual - (pretax_deductions * pay_periods)
fed_tax_annual = 0
prev = 0
for limit, rate in brackets:
if taxable_annual <= prev:
break
fed_tax_annual += min(taxable_annual, limit) * rate - prev * rate
prev = limit
federal_tax = fed_tax_annual / pay_periods
ss_tax = min(gross, 168600 / pay_periods) * 0.062
medicare_tax = gross * 0.0145
state_tax = gross * state_tax_rate
total_deductions = pretax_deductions + federal_tax + ss_tax + medicare_tax + state_tax
net = gross - total_deductions
return {
"gross": round(gross, 2),
"federal_tax": round(federal_tax, 2),
"social_security": round(ss_tax, 2),
"medicare": round(medicare_tax, 2),
"state_tax": round(state_tax, 2),
"pretax_deductions": round(pretax_deductions, 2),
"net": round(net, 2)
}
result = calculate_paycheck(75000, "single", 0.05, 0.06, 200, 50, 26)
print(f"Gross: ${result['gross']:,.2f}")
print(f"Net Pay: ${result['net']:,.2f}")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.