0

So this is my code and i have made the federal tax part of my calculator work but i can't seem to make the state tax part of my calculator work.i keep getting errors. does anyone know how to resolve this. i am a beginner :)

def come():
    while True:
        try:

            print("Error: come `")

            continue
        else:
            break

    return i


def tax(income):
    if income <= 0000:
        tax = ome * 0.10
    elif income <= 0000: 
        tax = (ome - .5) * 0.12 
    


    come = come()
    tax = tax(0000)
0000        
0000 


      
if __name__ == "__main__":
   inco

1 Answers1

1

your program has some logic and syntax errors (some earlier posts had pointed out). Here is a working version that may be helpful for you to work out the final version. (I've tried to minimize the changes on purpose, so that you can continue working on you own)

def read_income():
    while True:
        try:

            income = int(input("Enter your gross income: "))
            state =  input("What state do you reside in: ")  # string
        except ValueError:
            print("Error: Income format incorrect enter <number only>")
            continue
        else:
            break

    return income, state


def calculate_tax(income):
    income_bracket = [0.10, 0.12, 0.22, 0.24, 0.32, 0.35, 0.37]
    #                   0    1    2     3     4     5     6
    
    #deductibles = [98.5, 4617.5, 14605.5]   # this should be better DS.
    
    if income <= 9875:
        tax = income * income_bracket[0]
    elif 9876 < income <= 40125: 
        tax = (income - 98.5) * income_bracket[1]
    elif income <= 85525:
        tax = (income - 4617.5) * income_bracket[2]
    elif income <= 163300:
        tax = (income - 14605.5) * income_bracket[3]
    elif income <= 207350:
      tax = (income - 33271.5) * income_bracket[4]
    elif income <= 518400:
      tax = (income - 47367.5) * income_bracket[5]
    elif income >= 518401:
      tax = (income - 156235) * income_bracket[6]

    return tax


if __name__ == "__main__":
    income, state = read_income()
    tax =  calculate_tax(income)
    print('You payed an amount of', tax, 'in tax', 'you are left with',income - tax)
    
stateTax = {"alabama": .04, "alaska": 1, "arizona": .035, "arkansas": .06, "california": .09, "colorado": .0463,
            "connecticut": .05, "delaware": 0.066, "florida": 1, "georgia": 0.0575, "hawaii": .08, "idaho": 0.06625,
            "illinois": 0.0495, "indiana": 0.0323, "iowa": .04, "kansas": .0435,}
#for state, rate in stateTax.items():
#    print(state, rate) 

Output:

Enter your gross income: 45000
What state do you reside in: iowa
You payed an amount of 8884.15 in tax you are left with 36115.85
>>> 
Daniel Hao
  • 4,922
  • 3
  • 10
  • 23
  • 1
    Rather than making income_bracket a single list, make it a table (list of lists), so that it also has the thresholds etc, then process it in a loop? – Jiří Baum Jan 12 '21 at 03:11
  • 1
    Good idea. It's good to leave that for the author to work out... ;-) – Daniel Hao Jan 12 '21 at 03:13