r/pythonhelp • • Jul 30 '21

HOMEWORK need help with python tax calculator

I'm new to python. Made a simple calculator for tax but want to add 12000 personal allowance in - so if the salary is <= 12,000 the 20% tax should no be deducted - also if the salary is 13,000 the 20% should be deducted from the 1000.

right now it works - but the 20% is deducted from everything

hours = input ("Number of Hours Per Week? ")

rate = input ("Your Hourly Rate? ")

wp = float(hours) * float(rate)

#wp is weekly pay

print ("weekly pay: ", wp)

#mp is monthly pay

mp = float(wp) * 4

print ("Monthly Pay: ", mp)

salary = float(mp) * 12

print ("Yearly Salary: ", salary)

pa = 12000

print ("Personal Allowance: ", pa)

quotient = 1 / 5

tax = float(salary) * float(quotient)

print ("20% tax: ", tax)

#sat means salary after tax

sat = float(salary) - float(tax)

print ("Salary after tax & PA: ", sat)

mat = float(sat) / 12

print ("Monthly Pay after tax & PA: " ,mat)

3 Upvotes

2 comments sorted by

4

u/MrPhungx Jul 31 '21

Well... Of course the 20% is deducted from everything. You need to add an if statement. Just below your pa line you can add Something like this:

if salary > pa: tax = float(salary) * 0.2 ...

1

u/skellious Aug 08 '21

Tax should only be deducted on the amount over the personal allowance.

So:

if salary > pa: tax = float(salary-pa) * 0.2 ...