0
我一直收到「int」對象沒有屬性「txinc」的錯誤。我不知道如何解決這個問題。我的最終產出應該是總稅。錯誤發生在稅務計算器中,特別是範圍函數。它應該是一個整數。AttributeError「int」Object沒有屬性'txinc'
import sys
class TaxComp:
def __init__(self, total_deductions= None, real_estate_deduc= None, exemption_amount= None, taxable_income= None, tax_taxable_income= None,
computed_regular_tax= None, inc_tax_before_credits= None, inc_subject_to_tax= None, marginal_tax_base= None, tax_generated= None, AMT= None):
self.total_deductions = total_deductions or 'total_deductions'
self.real_estate_deduc = real_estate_deduc or 'real_estate_deduc'
self.exemption_amount = exemption_amount or 'exemption_amount'
self.taxable_income = taxable_income or 'taxable_income'
self.tax_taxable_income = tax_taxable_income or 'tax_taxable_income'
self.computed_regular_tax = computed_regular_tax or 'computed_regular_tax'
self.inc_tax_before_credits = inc_tax_before_credits or 'inc_tax_before_credits'
self.inc_subject_to_tax = inc_subject_to_tax or 'inc_subject_to_tax'
self.marginal_tax_base = marginal_tax_base or 'marginal_tax_base'
self.tax_generated = tax_generated or 'tax_generated'
self.AMT = AMT or 'AMT'
class TaxableIncome:
def taxable_Income(self, AGI):
taxable_inc = AGI - 6300
taxable_inc -= 4000
class Totals:
txcomp = TaxComp()
def __init__(self, taxable_income = txcomp.taxable_income):
txinc = TaxableIncome()
self.taxable_income = taxable_income or txinc.taxable_Income.taxable_inc
class TaxCal:
def __init__(self):
self.brackets = {(0,8025):0.10, (8025,32550):.15, (32550,78850):.25, (78850, 164550):.28, (164550,357700):.33, (357700,371815):.35, (371815, sys.maxsize):.396}
def taxcal (self, tot):
tax = 0
for bracket in self.brackets:
if tot.txinc.taxable_Income.taxable_inc > bracket[0]:
for _ in range(bracket[0], min(int(tot.txinc.taxable_Income.taxable_inc), bracket[1])):
tax += self.brackets[bracket]
return tax
AGI = 100000
txcal = TaxCal()
tot = Totals()
print(txcal.taxcal(AGI)), format(round(txcal.taxcal(AGI),2))
不幸的仍然產生相同的錯誤 –
對不起,我錯過了你正在將AGI傳遞給taxal,它將total作爲類總計。 也許你想「如果tot.txinc.taxable_Income.taxable_inc>括號[0]:」只是「如果tot>括號[0]:」 –
也沒有運氣。儘管我很欣賞這個幫助! –