我有一個FUNC calculate_tax應該採取名字:薪酬對作爲一個參數,計算則納稅申報名字的字典:total_tax對但是,似乎並沒有正確計算稅收。我可能做錯了什麼?下面是代碼:傳遞一個字典功能,操縱值並返回一個字典
def calculate_tax(**data):
for key in data:
if data[key] > 0 and data[key] <= 1000:
data[key] = 0
elif data[key] > 1000 and data[key] <= 10000:
data[key] += (data[key]-1000)*0.1
elif data[key] > 10000 and data[key] <= 20200:
data[key] += (data[key]-10000)*0.15
elif data[key] > 20200 and data[key] <= 30750:
data[key] += (data[key]-20200)*0.2
elif data[key] > 30750 and data[key] <= 50000:
data[key] += (data[key]-30750)*0.25
elif data[key] > 50000:
data[key] += (data[key]-50000)*0.3
return data
的稅率是:
Yearly Income: 0 - 1000
Tax Rate: 0%
Yearly Income: 1,001 - 10,000
Tax Rate: 10%
Yearly Income: 10,001 - 20,200
Tax Rate: 15%
Yearly Income: 20,201 - 30,750
Tax Rate: 20%
Yearly Income: 30,751 - 50,000
Tax Rate: 25%
Yearly Income: Over 50,000
Tax Rate: 30%
例如,假設當:
{'Ken':500,'Patrick':20500,'Winnie':70000}
它應該返回帕特里克稅2490
我得到的結果是:{'Patrick':20560.0,'Ken':0,'Winnie':76000.0}這似乎是錯誤的 – Hillux
'帕特里克':20500 - 它應該返回帕特里克稅爲2490' - 爲什麼?這將是'20500 +(20500 - 20200)* 0.2 = 2560' –
@Hillux可以提供您想要使用數學表達式計算稅款的方式嗎?您錯過了操作順序優先順序。 – direprobs