看看你的年终奖发的是否合理:
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
def getTaxRatio(taxSalary):
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
ratiolist =(
(500, 0.05, 0),
(2000, 0.10, 25),
(5000, 0.15, 125),
(20000, 0.20, 375),
(40000, 0.25, 1375),
(60000, 0.30, 3375),
(80000, 0.35, 6375),
(100000, 0.40, 10375),
(9999999,0.45, 15375)
)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
if taxSalary>= 0:
for ratio in ratiolist:
if taxSalary<= ratio[0]:
return (ratio[1], ratio[2])
return (0, 0)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
def calcYearAwardTax(yearAward):
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
monthAward = yearAward / 12
taxRatio, taxAdjust = getTaxRatio(monthAward)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
tax = yearAward * taxRatio - taxAdjust
resultAward = yearAward - tax
retcode = (yearAward, resultAward, tax, taxRatio, taxAdjust)
#print('yearAward= %d, resultAward= %f, tax= %f, taxRatio= %f, taxAdjust= %d'%retcode)
return retcode
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
################################################################################
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
import sys
import os
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
argNum = len(sys.argv)
if argNum == 1:
scriptName = os.path.basename(__file__)
print('usage1: %s awardUpperBound'%scriptName)
print('usage2: %s awardLowerBound awardUpperBound'%scriptName)
sys.exit()
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
print('-----------------------------------------------------------------------')
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
awardLowerBound, awardUpperBound = 0, 0
if argNum == 2:
awardUpperBound = int(sys.argv[1])
elif argNum == 3:
awardLowerBound, awardUpperBound = int(sys.argv[1]), int(sys.argv[2])
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
if awardLowerBound> awardUpperBound:
swap(awardLowerBound, awardUpperBound)
perfectAward, perfectGain = 0, 0
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
for award in range(awardLowerBound, awardUpperBound + 1):
retcode = calcYearAwardTax(award)
if len(retcode) > 2:
if retcode[1]> perfectGain:
perfectAward = retcode[0]
perfectGain = retcode[1]
if award== awardUpperBound:
print('upperBoundAward= %d,\tgain= %f,\ttax= %f'%(retcode[0], retcode[1], retcode[0] - retcode[1]))
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
print("perfectAward= %d,\tgain= %f,\ttax= %f"%(perfectAward, perfectGain, perfectAward - perfectGain))
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
保存成文件 awardTax.py 然后在命令行调用即可。
比如你年终奖发了25000,则:
![](http://www.cppblog.com/images/cppblog_com/xmli/yearAwardTax.JPG)
ok, 那么你亏了,你比拿24000的同志多交税3625-2375= 1250元,最终收益还比他少21625-21375= 250元。
这个数值段最佳的年终奖数额为24000,因此还是向老板申请少给你发点年终奖吧。