Python 我无法在薪俸税计算器中计算税收函数
我正在构建一个薪俸税计算器,这是我的第一个单独项目,但在以下情况下无法计算函数: 当工资在10万到12.5万之间时,国民保险费和 50024起征点后国民保险税的2% 所得税的20%,直至50000 50000起征点后所得税的40% 如果您的收入超过100000英镑,则12500英镑的标准个人津贴每2英镑收入减少1英镑。 我设法正确计算了国民保险费、个人免税额,但我无法计算所得税。你能告诉我,我收到的所得税数字不正确,我做错了什么吗Python 我无法在薪俸税计算器中计算税收函数,python,calculator,tax,Python,Calculator,Tax,我正在构建一个薪俸税计算器,这是我的第一个单独项目,但在以下情况下无法计算函数: 当工资在10万到12.5万之间时,国民保险费和 50024起征点后国民保险税的2% 所得税的20%,直至50000 50000起征点后所得税的40% 如果您的收入超过100000英镑,则12500英镑的标准个人津贴每2英镑收入减少1英镑。 我设法正确计算了国民保险费、个人免税额,但我无法计算所得税。你能告诉我,我收到的所得税数字不正确,我做错了什么吗 result = (int(input('What is you
result = (int(input('What is your annual salary? ')))
taxable_income = (result - 12500)
if result > 100000 and result <= 125000:
if taxable_income%2==0:
taxable_income += (result-100000)/2
if taxable_income%2 == 1:
taxable_income += (result-100001)/2
tax_free_allowance = (result - taxable_income)
total_taxable = result - tax_free_allowance
result_deduct5 = 12360 + ((result - 50000) * 0.02) + ((total_taxable - 50000) * 0.4)
#the 12,360 here is tax to be paid for both national insurance and income up to 50,000 threshold
result5 = result - result_deduct5 - personal_allowance_deduct
print(f'Your take home salary = {result5}')
整个代码如下:
# taxable income amounts thresholds
personal_tax = 12500 # allowance threshold
basic_tax = 50000
higher_tax = 150000
additional_tax = 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999
def earnings_personal_tax(earnings):
if earnings <= personal_tax:
return earnings * 0 # 0% tax rate for basic_tax
def earnings_basic_tax(earnings):
if earnings > personal_tax and earnings <= basic_tax:
earnings -= personal_tax # Only the part of your earnings that exceeds personal tax is taxed.
return earnings * .2 # 20% tax rate for basic_tax
def earnings_higher_tax(earnings):
if earnings > basic_tax and earnings <= higher_tax:
earnings -= personal_tax
return earnings * .4 # 40% tax rate for higher_tax salary between 50k and 150k
def earnings_additional_tax(earnings):
if earnings > higher_tax:
earnings -= personal_tax
return earnings * .45 # highest tax rate for additional_tax salary above 150k
#National Insurance
#you pay National Insurance contributions if you earn more than £183 a week for 2020-21
#you pay 12% of your earnings above this limit and up to £962 a week for 2020-21
#the rate drops to 2% of your earnings over £962 a week.
#For example, if you earn £1,000 a week, you pay:
#nothing on the first £183
#12% (£93.48) on the next £779
#2% (£0.76) on the next £38.
# yearly thresholds of national insurance conttributions
below = 9516 # below this amount there is no national insurance to be paid
within = 50024 # between 9,516 and 50,024 there is 12% of earnings to be contributed to national insurance
# over 'within' threshold the rate drops to 2% of your earnings
def nin_below_threshold(earnings):
if earnings <= below:
return earnings * 0 # 0% tax rate for basic_tax
def nin_within_threshold(earnings):
if earnings > below and earnings <= within:
earnings -= below # Only the part of your earnings that exceeds personal tax is taxed.
return earnings * .12
def nin_above_threshold(earnings):
if earnings > within:
w = (earnings - within) * 0.02
earnings -= below
return 4860 + w
result = (int(input('What is your annual salary? ')))
# when salary is lower than 9,516 then there is 0% of tax
if result <= 9516:
print(f'Your take home salary = {result}')
# when salary is between 9,516 and 12,500 then there is
# 12% of tax from national insurance conttributions and
# 0% of income tax
if result > 9516 and result <= 12500:
result = result - nin_within_threshold(result) - earnings_personal_tax(result)
print(f'Your take home salary = {result}')
# when salary is between 12,500 and 50,000 then there is
# 12% of tax from national insurance conttributions and
# 20% of income tax
if result > 12500 and result < 50000:
result3 = result - nin_within_threshold(result) - earnings_basic_tax(result)
print(f'Your take home salary = {result3}')
# result3 is 12% of NI tax and 20% of Income Tax i.e. Tax received between 0 and 50,000
# when salary is between 50,000 and 150,000 then there is
# 12% of tax from national insurance conttributions and
# 2% of tax from national insurance conttributions after 50,024 threshold
##20% of income tax until 50,000
# 40% of income tax after 50,000 threshold
if result > 50000 and result <= 100000:
# 12,360 = tax below 50,000
result_deduct4 = 12360 + ((result - 50000) * 0.02) + ((result - 50000) * 0.4)
result4 = result - result_deduct4
print(f'Your take home salary = {result4}')
# when salary is between 100,000 and 125,000 then there is
# 12% of tax from national insurance conttributions and
# 2% of tax from national insurance conttributions after 50,024 threshold
##20% of income tax until 50,000
# 40% of income tax after 50,000 threshold
# if you earn over £100,000, the standard Personal Allowance of £12,500 is reduced by £1 for every £2 of income.
taxable_income = (result - 12500)
allowance = 12500
income = int(input("Input your income: "))
if income > 100000:
allowance -= income / 2
if result > 100000 and result <= 125000:
if taxable_income % 2 == 0:
taxable_income += (result - 100000) / 2
if taxable_income % 2 == 1:
taxable_income += (result - 100001) / 2
tax_free_allowance = (result - taxable_income)
total_taxable = result - tax_free_allowance
result_deduct5 = 12360 + ((result - 50000) * 0.02) + ((total_taxable - 50000) * 0.4)
result5 = result - result_deduct5 - personal_allowance_deduct
print(f'Your take home salary = {income}')
你的意思是这样的:
allowance = 12500
income = int(input("Input your income: "))
if income > 100000:
allowance -= income/2
你的工资到底有什么问题?我在计算后收到的结果与其他工资计算器(例如?)相比是不正确的。我调查了可能的原因,发现在我的代码中,国民保险税和津贴(每2英镑收入减少1英镑)的计算是正确的。但是所得税总是给我一个错误的答案,我不知道为什么?刚刚在下面发布了我的全部代码,在我试图计算100 Kyes以上的工资之前,所有函数都有效,津贴最高为12500,100000之后开始减少,直到达到0。因此,在125,00时,容差将达到零,但不能为负。我应该把我的全部密码寄给你吗?这只是一个可能让一切都难以理解的部分?仅添加以下内容: