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
>>>