Demo entry 6785243

assignment

   

Submitted by Xu on Mar 14, 2019 at 13:13
Language: Python 3. Code size: 3.4 kB.

# 2019 工资计算器
ALLCumulativeWithholdingTaxableIncome = [0, 36000, 144000, 300000, 420000, 660000, 960000]
AllTaxRates = [0.03, 0.10, 0.20, 0.25, 0.30, 0.35, 0.45] # 税率
AllQuickCalculationDeductions = [0, 2520, 16920, 31920, 52920, 85920, 181920] # 速算扣除数
TaxExemptionThreshold = 5000 # 起征点

# 累计应扣预缴纳税所得额
def cumulative_withholding_taxable_income(Salary, month, Social_insurance_premiums, special_additional_deduction):
	return max([Salary - TaxExemptionThreshold * month - Social_insurance_premiums*month - special_additional_deduction*month, 0])

# 得到适用税率 和 速算扣除数
def get_withholding_tax_rate(CWTI): # 累计应扣预缴纳税所得额 cumulative_withholding_taxable_income
	pos = 0
	leng = len(ALLCumulativeWithholdingTaxableIncome)
	while pos < leng:
		if CWTI <= ALLCumulativeWithholdingTaxableIncome[pos]:
			break
		pos += 1
	if pos == leng:
		pos -= 1
	return max([pos-1, 0])

# 累计预扣预缴税额
def Cumulative_withholding_tax_in_advance(CWTI, pos): # 累计应扣预缴纳税所得额 cumulative_withholding_taxable_income 
	withholding_tax_rate = AllTaxRates[pos]
	quick_calculation_deduction = AllQuickCalculationDeductions[pos]
	return CWTI * withholding_tax_rate - quick_calculation_deduction

# input
Salary = 0
last_Salary = 0;
month = int(input(" 纳税期数(月份 1—12): ")) # 需计算的月份
flag = int(input(" 是否每月薪酬相同?(是输入1,否则输入0) : "))
if flag:
	MonthlySalary = int(input(" 月薪 : ")) # 月薪	
	Salary = month * MonthlySalary
	last_Salary = (month-1) * MonthlySalary
else :
	print(" ~~请输入每个月的薪酬~~")
	for i in range(month):
		MonthlySalary = int(input(" 请输入 {} 月薪酬 : ".format(i+1)))
		if i == month-1:
			Salary = last_Salary + MonthlySalary
		else :
			last_Salary += MonthlySalary;
Social_insurance_premiums = int(input(" 专项扣除(各项社会保险费) : ")) # 各项社会保险费
special_additional_deduction = int(input(" 专项附加扣除 : ")) # 专项附加扣除
# 计算
print(" \n结果 : ")
# 本月累计应扣预缴纳税所得额
the_month_cumulative_withholding_taxable_income = cumulative_withholding_taxable_income(Salary, month, Social_insurance_premiums, special_additional_deduction)
print(" {} 月累计应扣预缴纳税所得额 : {}".format(month, the_month_cumulative_withholding_taxable_income))
the_last_month_cumulative_withholding_taxable_income = cumulative_withholding_taxable_income(last_Salary, month-1, Social_insurance_premiums, special_additional_deduction)

# 税率
# 本月适用税率
pos0 = get_withholding_tax_rate(the_month_cumulative_withholding_taxable_income)
withholding_tax_rate = AllTaxRates[pos0]
print(" 适用税率 : %d%%" % (withholding_tax_rate*100))
last_pos = get_withholding_tax_rate(the_last_month_cumulative_withholding_taxable_income)

# 速算扣除数
the_month_QuickCalculationDeductions = AllQuickCalculationDeductions[pos0]
print(" 速算扣除数 : ", the_month_QuickCalculationDeductions)

# 累计预扣预缴税额
the_month_Cumulative_withholding_tax_in_advance = Cumulative_withholding_tax_in_advance(the_month_cumulative_withholding_taxable_income, pos0)
the_last_Cumulative_withholding_tax_in_advance = Cumulative_withholding_tax_in_advance(the_last_month_cumulative_withholding_taxable_income, last_pos)

This_month_withholding_tax = the_month_Cumulative_withholding_tax_in_advance - the_last_Cumulative_withholding_tax_in_advance
print(" %d 月应扣缴税额 : %.2f" %(month, This_month_withholding_tax))
take_home_pay = (Salary - last_Salary) - Social_insurance_premiums - This_month_withholding_tax
print(" %d 月实的工资 : %.2f" %(month, take_home_pay))

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).