我正在尝试构建此计税器并继续收到此错误:
'float'对象不能解释为整数
问题似乎是我的range
行,但我无法弄清楚如何修复它。
class taxCalc:
def __init__(self):
self.brackets_single = {(0,10000):0.15, (10000,45000):.18, (45000,72000):.23, (72000, sys.maxsize):.38}
self.brackets_joint = {(0,20000):0.15, (20000,90000):.18, (90000,144000):.23, (144000, sys.maxsize):.38}
def taxcal(self, income, fil_stat, depen, stdeduc):
if stdeduc == 'TRUE':
if fil_stat == 'single':
agincome = income - 1000
elif fil_stat == 'joint':
agincome = income - 2000
else: agincome = income
if depen == 1:
agincome -= 1000
elif depen == 2:
agincome -= 2000
else:
agincome = income
PEP = .02
if agincome >= 45000 :
amount = agincome - 45000
amount /= 1000
amount *= PEP
amount *= (1000*depen)
if 1000*depen - amount > 0:
agincome += amount
else:
agincome += (1000*depen)
else: agincome = agincome
tax = 0
if fil_stat == 'single':
for bracket in self.brackets_single:
if agincome > bracket[0]:
for _ in range(bracket[0], min(agincome, bracket[1])):
tax += self.brackets_single[bracket]
elif fil_stat == 'joint':
for bracket in self.brackets_joint:
if agincome > bracket[0]:
for _ in range(bracket[0], min(agincome, bracket[1])):
tax += self.brackets_joint[bracket]
return tax
mytest=taxCalc()
print(mytest.taxcal(75000, 'single', 1, 'TRUE')), format(round(mytest.taxcal(75000, 'single', 1, 'TRUE'),2))