簡體   English   中英

python 新手,無法弄清楚為什么扣除額不包括稅收

[英]New to python and having trouble figuring out why the deductions are not including the tax in the total

我是編程新手,我正在嘗試為我所在的 Python 基礎課程編寫一個程序。這是在第 1 天,我無法弄清楚為什么總扣除額不會計算出正確的金額。 這是我寫的代碼:

    print("=================DEDUCTIONS=================")

print("SSS: " + sss_contribution)
print("PhilHealth: " + philhealth_contribution)
print("Other Loan: " + housing_loan)

tax_rate = .10
tax_total = int(gross_salary)*int(tax_rate)
print("Tax: " + str(tax_total))

total_deductions = int(sss_contribution) + int(philhealth_contribution) + int(housing_loan) + int(tax_total)
print("Total Deductions: " + str(total_deductions))

net_salary = float(gross_salary) - float(total_deductions)

print("NET SALARY: " + str(net_salary))

我得到了正確的 NET SALARY 金額,但總扣除額僅反映 SSS、PhilHealth 和 Housing 的總和。 謝謝你。

您將 tax_rate 聲明為浮點數,因此請嘗試:

tax_total = int(gross_salary)*float(tax_rate)

如果您將 tax_rate 聲明為 5.10,則執行 int(tax_rate) 返回 5。而執行 float(tax_rate) 返回 5.1。

在您的示例中,您將 tax_rate 聲明為 0.10,因此您的 tax_total 變為 0,因為 int(tax_rate) 為 0。這就是為什么您的稅不包括在您的計算中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM