为什么对象被解释为 int 而不是 float。
main2 = True
while main2:
try:
amount = float(input('annual gross income: '))
namount = float(amount)
expenses = float(input('annual expenses: '))
nnexpenses = float(expenses)
if(9226 <= namount <= 37450):
print('Your tax rate is $922.50 + 15%')
print(float(round(namount - namount*0.15 - 922.50 - nnexpenses)))
if(namount <= 9225):
print('Your tax rate is 10%')
print(float(round(namount - namount*0.10 - nnexpenses,2)))
if(37451 <= namount <= 90750 ):
print('Your tax rate is $5, 156.25 + 25%')
print(float(round(amount - namount*0.25 - 5,156.25 - nnexpenses)))
if(90751 <= namount <= 189300):
print('Your tax rate is $18,481.25 + 28%')
print(float(round(amount - namount*0.28 - 18,481.25 - nnexpenses)))
if(189301 <= namount <= 411500):
print('Your tax rate is $46,075.25 + 33%')
print(float(round(namount - namount*0.33 - 46,075.25 - nnexpenses)))
if(411501 <= namount <= 413200):
print('Your tax rate is $119,401.25 + 35%')
print(float(round(namount - namount*0.35 - 119,401.25 - nnexpenses)))
if(413201 <= namount):
print('Your tax rate is $119,996.25 + 39.6%')
print(float(round(namount - namount*0.396 - 119,996.25 - nnexpenses)))
#print('Annual Net Income: ', round(result,2))
except(ValueError,NameError):
#if(ValueError):
print('Please enter a number and postive balance.')
#else:
#print('Get out of debt')
最佳答案
删除数字中的逗号。逗号被解释为参数分隔符,这意味着使用两个参数而不是一个参数调用 round
。
print(float(round(namount - namount*0.35 - 119,401.25 - nnexpenses)))
应该是
print(float(round(namount - namount*0.35 - 119401.25 - nnexpenses)))
关于python - 类型错误: 'float' 对象无法解释为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32687012/