0

I'm building a salary tax calculator (my first solo project) but am unable to calculate function for the following conditions:

  • 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.

I managed to calculate national insurance contributions, personal allowance correctly, however, I am not able to figure out the income tax. Could you please advise what am I doing wrong that the income tax numbers I am receiving are not correct?

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}') 

the entire code below:

# 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}') 







Christopher
  • 57
  • 1
  • 5
  • What exactly is the problem with what you have? – mkrieger1 Jun 18 '20 at 18:12
  • The result I am receiving after calculations is incorrect when I compare it with other salary calculators e.g. https://listentotaxman.com/69000? . I investiaged what could be the reason and found that both national insurance tax and allowance which is reduced by £1 for every £2 of income are calculated correctly in my code. But the income tax always gives me a wrong answer and I have no idea why? Just posted my whole code below, all functions there work until I try to calculate salary above 100k – Christopher Jun 19 '20 at 05:14

1 Answers1

1

You mean like this:

allowance = 12500
income = int(input("Input your income: "))

if income > 100000:
    allowance -= income/2
Red
  • 26,798
  • 7
  • 36
  • 58
  • yes, allowance is up to 12,500 and after 100,000 it starts decreasing until it reaches 0. Hence, at 125,00 allowance will reach zero but cannot be negative. Should I send you my whole code? This is just a part which might make everything hard to understand? – Christopher Jun 18 '20 at 18:38
  • just added below :) – Christopher Jun 19 '20 at 05:14