python练习-工资计算器

来源:互联网 发布:rtl8152b linux驱动 编辑:程序博客网 时间:2024/04/28 18:44

python练习-工资计算器

源代码如下:

#! /usr/bin/env pythondef 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_feedef get_wancan_buzhu():    buzhu = (raw_input("Please input your supper buzhu times: "))    if len(buzhu) == 0:        buzhu = 0    return float(buzhu) * 10def get_shebao_jishu():    basic = (raw_input("Please input your shebao jishu <eg: 2697>: "))    if len(basic) == 0:        basic = 2697    basic = float(basic)    if basic < 2697:        print "ERROR: Input invalid."        exit(1)    return basicdef 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 baoxiandef 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.4def 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_sallarydef 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_taxdef 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_salaryprint ("Final salary: %.3f" % get_final_salary())raw_input("Press <Enter> to continue.")


python练习-工资计算器

0 0
原创粉丝点击