python练习-工资计算器

源代码如下:

#! /usr/bin/env python

def get_user_salary_sum():

salary = (raw_input("Please input your salary: "))

if len(salary) == 0:

salary = 0

print ("ERROR: Input invalid.")

exit(1)

return float(salary)

def get_user_jiaban_hours():

hours = (raw_input("Please input your jiaban hours: "))

if len(hours) == 0:

hours = 0

return float(hours)

def get_jiaban_salary(salary, hours):

jiaban_fee = hours * salary / 174 * 2

return jiaban_fee

def get_wancan_buzhu():

buzhu = (raw_input("Please input your supper buzhu times: "))

if len(buzhu) == 0:

buzhu = 0

return float(buzhu) * 10

def get_shebao_jishu():

basic = (raw_input("Please input your shebao jishu : "))

if len(basic) == 0:

basic = 2697

basic = float(basic)

if basic < 2697:

print "ERROR: Input invalid."

exit(1)

return basic

def get_shebao_e():

return 0.185 * get_shebao_jishu()

def get_5xian1jin():

# baoxian = float(raw_input("Please input your 5xian + 1jin: "))

baoxian = get_shebao_e()

return baoxian

def get_personal_leave_hours():

pl_hours = (raw_input("Please input your personal leave hours: "))

if len(pl_hours) == 0:

pl_hours = 0

return float(pl_hours)

def get_personal_leave_fee(salary):

return salary / 174 * get_personal_leave_hours()

def get_ill_leave_hours():

il_hours = (raw_input("Please input your ill leave hours: "))

if len(il_hours) == 0:

il_hours = 0

return float(il_hours)

def get_ill_leave_fee(salary):

return salary / 174 * get_ill_leave_hours() * 0.4

def get_total_salary():

salary = get_user_salary_sum()

hours = get_user_jiaban_hours()

total_sallary = salary + get_wancan_buzhu() + get_jiaban_salary(salary, hours) - get_5xian1jin()

total_sallary -= get_personal_leave_fee(salary) + get_ill_leave_fee(salary)

return total_sallary

def get_salary_tax(total):

sum_total = total

stage = [3500, 1500, 4500, 9000, 35000, 55000, 80000, ]

tax = [0.00, 0.03, 0.10, 0.20, 0.25, 0.30, 0.35, 0.45]

tax_stage = [0,] * len(tax)

for i, x in enumerate(stage):

for j in range(i + 1):

tax_stage[i] += int(stage[j])

fast = [0, 105, 555, 1005, 2755, 5505, 13505]

salary_tax = 0;

index_num = 0

if sum_total <= tax_stage[0]:

return 0

elif tax_stage[0] < sum_total <= tax_stage[1]:

index_num = 1

elif tax_stage[1] < sum_total <= tax_stage[2]:

index_num = 2

elif tax_stage[2] < sum_total <= tax_stage[3]:

index_num = 3

elif tax_stage[3] < sum_total <= tax_stage[4]:

index_num = 4

elif tax_stage[4] < sum_total <= tax_stage[5]:

index_num = 5

elif tax_stage[5] < sum_total <= tax_stage[6]:

index_num = 6

else:

index_num = 7

sum_total -= stage[0]

salary_tax += sum_total * tax[index_num] - fast[index_num - 1]

return salary_tax

def get_final_salary():

total = get_total_salary()

salary_tax = get_salary_tax(total)

print ("Tax: %.3f" % salary_tax)

final_salary = total - salary_tax

return final_salary

print ("Final salary: %.3f" % get_final_salary())

raw_input("Press to continue.")

python练习-工资计算器

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐