Reputation: 3
so i'm learning python and decided to program a payroll for my company as practice. for the usa bi-weekly tax, there is pattern to the amount you need to pay, here is a short code for example
if n >= 760 and n < 780: gt = 45 if n >= 780 and n < 800: gt = 47 if n >= 800 and n < 820: gt = 49 if n >= 820 and n < 840: gt = 51
here n is the salary, and gt is the tax to be paid.
as you can see, the range of n is a constant 20, and tax increase by a constant 2
this is true from 720 - 1000, starting from 1000 however, the rate of the tax increases by constant 3
i want to to be able to include a salary range from 720 to 2000, is there a way to do this, or do i have to do it the hard way and write them all out?
Upvotes: 0
Views: 182
Reputation: 776
I'd branch on your two ranges and then use some math to get the tax amount:
if n >= 720 and n < 1000:
gt = 2*(( n - 720 ) / 20) + 41
elif n >= 1000 and n < 2000:
gt = 3*(( n - 1000 ) / 20) + 67
Upvotes: 1