I recently created this Income Tax calculator based off your filing status (Single, or Married Filing Jointly) and which tax bracket you fall into for the 2020 tax year, taking into account the Standard deduction. I know the code is a little robust, but the math checks out as compared to several other tax calculators. I first posted it on Stack Overflow, which I now know was not the place for this, but please give any constructive advice you have.
How can I make this cleaner, as in, accomplish the same task with less code? Or if you have a different/more efficient way of writing any of this, I'm also interested. Update: Thank you everyone for your advice and input! I'll be taking this back to the whiteboard and making the suggested changes as I learn more. Your time and advice is appreciated, immensely!
marital_status = input("Filing Status (M / S): ")
household_income = int(input("household income: "))
if marital_status == "M":
standard_deduction = "24800"
# marrital standard deduction
elif marital_status == "S":
standard_deduction = "12400"
# single standard deduction
taxable_income = int(household_income) - int(standard_deduction)
married_bracket_caps = [19750, 80250, 171050, 326600, 414700, 622050]
# the above rates are the max dollar amount in the Married-filing-joint tax bracket(m/j)
single_bracket_caps = [9875, 40125, 85525, 163300, 207350, 518400]
# the above rates are the max dollar amount in the filing Single tax bracket
if marital_status == "M":
bracket = married_bracket_caps
elif marital_status == "S":
bracket = single_bracket_caps
#if M is entered, the future tax rates will abide by the m/j tax rates; #if
# S is entered than the taxt rates will abide by the Filing Single tax rates.
# ie. enter: M, the first tax rate will be "19750", computed as
if taxable_income <= int(bracket[0]):
tax = taxable_income * .1
elif taxable_income <= int(bracket[1]):
tax = (int(bracket[0]) * .1)+(.12*(taxable_income - int(bracket[0])))
elif taxable_income <= int(bracket[2]):
tax = (int(bracket[0]) * .1)+(.12*(int(bracket[1]) - int(bracket[0])))+(.22 * (taxable_income - int(bracket[1])))
elif taxable_income <= int(bracket[3]):
tax = (int(bracket[0]) * .1)+(.12*(int(bracket[1]) - int(bracket[0])))+(.22 * (int(bracket[2]) - int(bracket[1])))+(.24 * (taxable_income - int(bracket[2])))
print("taxable income: ", taxable_income)
print("owed in Federal tax: ", tax)
Note: The brackets for this calculator only go up four brackets because if I didn't want to do all the way up if I was going to need to rewrite it anyway. Again, thanks!
12
in the last two branches, or should it be.12
? \$\endgroup\$