Я создаю калькулятор налога на зарплату (мой первый индивидуальный проект), но не могу рассчитать функцию для следующих условий:
- когда зарплата от 100000 до 125000, тогда 12% налог с взносов национального страхования и
- 2% налога со взносов национального страхования после порога 50 024
- 20% налога на прибыль до 50 000
- 40% налога на прибыль после порога 50 000
- , если вы зарабатываете более 100 000 фунтов стерлингов, стандартное личное пособие в размере 12 500 фунтов стерлингов уменьшается на 1 фунт стерлингов на каждые 2 фунта стерлингов дохода.
Мне удалось правильно рассчитать взносы на государственное страхование, личное пособие, однако я не могу рассчитать подоходный налог. Не могли бы вы посоветовать, что я делаю не так, что получаемые мной налоговые номера неверны?
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}')