In: Computer Science
PLEASE DO THIS WITH PYTHON 3
Lab 4-2: Computing Tax
The United States federal personal income tax is calculated based on filing status and taxable income. There are four filing statuses: single filers, married filing jointly, married filing separately, and head of household. The tax rates vary every year. Table 3.2 shows the rates for 2009. If you are, say, single with a taxable income of $10,000, the first $8,350 is taxed at 10% and the other $1,650 is taxed at 15%. So, your tax is $1,082.5.
Table 1
2009 U.S. Federal Personal Tax Rates
|
Marginal Tax Rate |
Single |
Married Filing Jointly or Qualified Widow(er) |
Married Filing Separately |
Head of Household |
|
10% |
$0 – $8,350 |
$0 – $16,700 |
$0 – $8,350 |
$0 – $11,950 |
|
15% |
$8,351– $33,950 |
$16,701 – $67,900 |
$8,351 – $33,950 |
$11,951 – $45,500 |
|
25% |
$33,951 – $82,250 |
$67,901 – $137,050 |
$33,951 – $68,525 |
$45,501 – $117,450 |
|
28% |
$82,251 – $171,550 |
$137,051 – $208,850 |
$68,525 – $104,425 |
$117,451 – $190,200 |
|
33% |
$171,551 – $372,950 |
$208,851 – $372,950 |
$104,426 – $186,475 |
$190,201 - $372,950 |
|
35% |
$372,951+ |
$372,951+ |
$186,476+ |
$372,951+ |
You are to write a program to compute personal income tax. Your program should prompt the user to enter the filing status and taxable income and compute the tax. Enter 0 for single filers, 1 for married filing jointly, 2 for married filing separately, and 3 for head of household.
Here are sample runs of the program:
Sample 1:
Enter the filing status: 0
Enter the taxable income: 100000
Tax is 21720.0
Sample 2:
Enter the filing status: 1
Enter the taxable income: 300339
Tax is 76932.87
Sample 3:
Enter the filing status: 2
Enter the taxable income: 123500
Tax is 29665.5
Sample 4:
Enter the filing status: 3
Enter the taxable income: 4545402
Tax is 1565250.7
"""
Author:
Date :20/3/17
File Name:compute_tax.py
Description:
"""
def calculate_tax_single(income):
"""
This function compute tax for single filler
:param income:
:return:
"""
tax = 835.0
if 8350 < income <= 33950:
tax += (income - 8350) * 15 / 100
elif income > 33950:
tax += (33950 - 8350) * 15 / 100
if 33950 < income <= 82250:
tax += (income - 33950) * 25 / 100
elif income > 82250:
tax += (82250 - 33950) * 25 / 100
if 82250 < income <= 171550:
tax += (income - 82250) * 28 / 100
elif income > 171550:
tax += (171550 - 82250) * 28 / 100
if 171550 < income <= 372950:
tax += (income - 171550) * 33 / 100
elif income > 372950:
tax += (372950 - 171550) * 33 / 100
if income >= 372951:
tax += (income - 372950) * 35 / 100
return "{:.2f}".format(tax, 1)
def calculate_tax_married_joint(income):
"""
This function compute tax for married joint filler
:param income:
:return:
"""
tax = 16700 * 10 / 100
if 16700 < income <= 67900:
tax += (income - 16700) * 15 / 100
elif income > 67900:
tax += (67900 - 16700) * 15 / 100
if 67900 < income <= 137050:
tax += (income - 67900) * 25 / 100
elif income > 137050:
tax += (137050 - 67900) * 25 / 100
if 137050 < income <= 208850:
tax += (income - 137050) * 28 / 100
elif income > 208850:
tax += (208850 - 137050) * 28 / 100
if 208850 < income <= 372950:
tax += (income - 208850) * 33 / 100
elif income > 372950:
tax += (372950 - 208850) * 33 / 100
if income >= 372951:
tax += (income - 372950) * 35 / 100
return "{:.2f}".format(tax, 1)
def calculate_tax_married_separate(income):
"""
This function compute tax for married separate filler
:param income:
:return:
"""
tax = 835.0
if 8350 < income <= 33950:
tax += (income - 8350) * 15 / 100
elif income > 33950:
tax += (33950 - 8350) * 15 / 100
if 33950 < income <= 68525:
tax += (income - 33950) * 25 / 100
elif income > 68525:
tax += (68525 - 33950) * 25 / 100
if 68525 < income <= 104425:
tax += (income - 68525) * 28 / 100
elif income > 104425:
tax += (104425 - 68525) * 28 / 100
if 104425 < income <= 186475:
tax += (income - 104425) * 33 / 100
elif income > 186475:
tax += (186475 - 104425) * 33 / 100
if income >= 186476:
tax += (income - 186475) * 35 / 100
return "{:.2f}".format(tax, 1)
def calculate_tax_household(income):
"""
This function compute tax for household filler
:param income:
:return:
"""
tax = 11950.0 * 10 / 100
if 11950 < income <= 45500:
tax += (income - 11950) * 15 / 100
elif income > 45500:
tax += (45500 - 11950) * 15 / 100
if 45500 < income <= 117450:
tax += (income - 45500) * 25 / 100
elif income > 117450:
tax += (117450 - 45500) * 25 / 100
if 117450 < income <= 190200:
tax += (income - 117450) * 28 / 100
elif income > 190200:
tax += (190200 - 117450) * 28 / 100
if 190200 < income <= 372950:
tax += (income - 190200) * 33 / 100
elif income > 372950:
tax += (372950 - 190200) * 33 / 100
if income >= 186476:
tax += (income - 372950) * 35 / 100
return "{:.2f}".format(tax, 1)
if __name__ == '__main__':
while True:
filing_status = int(input("enter the filing status : ").strip())
taxable_income = float(input("Enter the taxable income :").strip())
if filing_status == 0:
print("Tax is", calculate_tax_single(taxable_income))
elif filing_status == 1:
print("Tax is", calculate_tax_married_joint(taxable_income))
elif filing_status == 2:
print("Tax is", calculate_tax_married_separate(taxable_income))
elif filing_status == 3:
print("Tax is", calculate_tax_household(taxable_income))
opt = input("Do you want to continue?Y/N:").strip()
if opt.lower() == "n":
break
output:
