This code follows the Joint account filings not the Singles account when I type in 0, I can't figure it out. Is it coded wrong? am I missing something? I cant figure out how to fix it. Thanks!
Problem Description: The United States federal personal income tax is calculated based on filing status and taxable income. There are four filing statuses: single filers and married filing jointly. 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) 10% $0 – $8,350 $0 – $16,700 15% $8,351– $33,950 $16,701 – $67,900 25% $33,951 – $82,250 $67,901 – $137,050 28% $82,251 – $171,550 $137,051 – $208,850 33% $171,551 – $372,950 $208,851 – $372,950 35% $372,951 $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 and 1 for married filing jointly.
#filings
Single = 0
Joint = 1
#amount taxed for singles
st1 = 8350
st2 = 25599
st3 = 48299
st4 = 89299
st5 = 201399
#filing brackets for singles
s1 = 8350
s2 = 33950
s3 = 82250
s4 = 171550
s5 = 372950
#amount taxed for joint
jt1 = 16700
jt2 = 51199
jt3 = 69149
jt4 = 71799
jt5 = 164099
#filings brackets for joint
j1 = 16700
j2 = 67900
j3 = 137050
j4 = 208850
j5 = 372950
#percents
p1 = 10/100
p2 = 15/100
p3 = 25/100
p4 = 28/100
p5 = 33/100
p6 = 35/100
#input of income and filings
filing = input('Enter the filing status:')
income = float(input('Enter the taxable income:'))
if filing==Single:
if income<=s1:
tax = income * p1
format_tax = "{:.2f}".format(tax)
print('Tax is', format_tax)
elif income>s1 and income<=s2:
i1 = income-st1
i2 = st1*p1
i3 = i1*p2
tax = i3 i2
format_tax = '{:.2f}'. format(tax)
print('Tax is', format_tax)
elif income>s2 and income<=s3:
i1 = income - st1
i2 = i1 - st2
tax1 = st1*p1
tax2 = st2*p2
tax3 = i2*p3
tax = tax1 tax2 tax3
format_tax = '{:.2f}'. format(tax)
print('Tax is', format_tax)
elif income>s3 and income<=s4:
i1 = income - st1
i2 = i1 - st2
i3 = i2 - st3
tax1 = st1*p1
tax2 = st2*p2
tax3 = st3*p3
tax4 = i3*p4
tax=tax1 tax2 tax3 tax4
format_tax = '{:.2f}'. format(tax)
print('Tax is', format_tax)
elif income>s4 and income<=s5:
i1 = income - st1
i2 = i1 - st2
i3 = i2 - st3
i4 = i3 - st4
tax1 = st1*p1
tax2 = st2*p2
tax3 = st3*p3
tax4 = st4*p4
tax5 = i4*p5
tax=tax1 tax2 tax3 tax4 tax5
format_tax = '{:.2f}'. format(tax)
print('Tax is', format_tax)
else:
i1 = income - st1
i2 = i1 - st2
i3 = i2 - st3
i4 = i3 - st4
i5 = i4 - st5
tax1 = st1*p1
tax2 = st2*p2
tax3 = st3*p3
tax4 = st4*p4
tax5 = st5*p5
tax6 = i5*p6
tax=tax1 tax2 tax3 tax4 tax5 tax6
format_tax = '{:.2f}'. format(tax)
print('Tax is', format_tax)
else:
if income <= j1:
tax = income * p1
format_tax = "{:.2f}".format(tax)
print('Tax is', format_tax)
elif income >j1 and income<=j2:
i1 = income-jt1
i2 = jt1*p1
i3 = i1*p2
tax = i3 i2
format_tax = '{:.2f}'. format(tax)
print('Tax is', format_tax)
elif income>j2 and income<=j3:
i1 = income - jt1
i2 = i1 - jt2
tax1 = jt1*p1
tax2 = jt2*p2
tax3 = i2*p3
tax = tax1 tax2 tax3
format_tax = '{:.2f}'. format(tax)
print('Tax is', format_tax)
elif income>j3 and income<=j4:
i1 = income - jt1
i2 = i1 - jt2
i3 = i2 - jt3
tax1 = jt1*p1
tax2 = jt2*p2
tax3 = jt3*p3
tax4 = i3*p4
tax=tax1 tax2 tax3 tax4
format_tax = '{:.2f}'. format(tax)
print('Tax is', format_tax)
elif income>j4 and income<=j5:
i1 = income - jt1
i2 = i1 - jt2
i3 = i2 - jt3
i4 = i3 - jt4
tax1 = jt1*p1
tax2 = jt2*p2
tax3 = jt3*p3
tax4 = jt4*p4
tax5 = i4*p5
tax=tax1 tax2 tax3 tax4 tax5
format_tax = '{:.2f}'. format(tax)
print('Tax is', format_tax)
else:
i1 = income - jt1
i2 = i1 - jt2
i3 = i2 - jt3
i4 = i3 - jt4
i5 = i4 - jt5
tax1 = jt1*p1
tax2 = jt2*p2
tax3 = jt3*p3
tax4 = jt4*p4
tax5 = jt5*p5
tax6 = i5*p6
tax=tax1 tax2 tax3 tax4 tax5 tax6
format_tax = '{:.2f}'. format(tax)
print('Tax is', format_tax)
CodePudding user response:
Your input() call returns a string, not an integer.
filing = input('Enter the filing status:')
By comparing filing
to Single
, you are comparing "1" to 1, which have different types and different values. As the variables had different values, your if statement evaluated to false, and your else statement was executed. What you likely meant to do is something like the following.
filing = int(input('Enter the filing status:'))
This converts the string into an integer, allowing you to directly compare it to Single
.
You can learn more about integer input in python here