python小练习(2)

人力系统
全职员工,兼职员工
属性:工号,姓名,全职月薪,兼职日薪、每月工作天数
方法:打印信息,计算月收入

 

# 人力系统
# 全职员工,兼职员工
# 属性:工号,姓名,全职月薪,兼职日薪、每月工作天数
# 方法:打印信息,计算月收入

class Employee:
    def __init__(self, s_name, s_id):
        self.s_name = s_name
        self.s_id = s_id

    def print_info(self):
        print("%s\t%s" % (self.s_id, self.s_name))


class FullTimeEmployee(Employee):
    def __init__(self, s_name, s_id, m_salary):
        super().__init__(s_name, s_id)
        self.FullTimeSalary = float(m_salary)

    def print_salary(self):
        print("salary:%.2f" % self.FullTimeSalary)


class PartTimeEmployee(Employee):
    def __init__(self, s_name, s_id, d_salary, day):
        super().__init__(s_name, s_id)
        self.d_salary = float(d_salary)
        self.day = int(day)

    def print_salary(self):
        PartTimeSalary = self.day * self.d_salary
        print("salary:%.2f" % PartTimeSalary)


i = 1
f = 1
while 1:
    print("""please select the service you need
    1.add employee
    2.print someone's info and salary
    3.print all info
    4.exit""")
    mode = input()
    if mode == '1':  # 添加员工
        repeat = 0
        s_class = input("is he full-time or part-time:(f/p)")
        if s_class == 'f':  # 添加全职员工
            s_id = input("input his id:")
            for j in range(1, i):
                if s_id == eval('f_employee' + str(j)).s_id:
                    print("this id has been used!")
                    repeat = 1
                    break
            if repeat != 1:  # id不重复
                s_name = input("input his name:")
                m_salary = input("input his monthly salary:")
                locals()['f_employee' + str(i)] = FullTimeEmployee(s_name, s_id, m_salary)
                print("create success!")
                i = i + 1

        elif s_class == 'p':  # 添加兼职员工
            s_id = input("input his id:")
            for j in range(1, f):
                if s_id == eval('p_employee' + str(j)).s_id:
                    print("this id has been used!")
                    repeat = 1
                    break
            if repeat != 1:  # id不重复
                s_name = input("input his name:")
                d_salary = input("input his daily salary:")
                day = input("input days he worked:")
                locals()['p_employee' + str(f)] = PartTimeEmployee(s_name, s_id, d_salary, day)
                print("create success!")
                f = f + 1
        else:
            print("error,try again!")

    elif mode == '2':
        selected = 0
        u_class = input("is he full-time or part-time:(f/p)")
        if u_class == 'f':
            u_id = input("input his id:")
            for j in range(1, i):
                if u_id == eval('f_employee' + str(j)).s_id:
                    selected = 1
                    eval('f_employee' + str(j)).print_info()
                    eval('f_employee' + str(j)).print_salary()
                    break
            if selected == 0:
                print("unselected,try again!")

        elif u_class == 'p':
            u_id = input("input his id:")
            for j in range(1, f):
                if u_id == eval('p_employee' + str(j)).s_id:
                    selected = 1
                    eval('p_employee' + str(j)).print_info()
                    eval('p_employee' + str(j)).print_salary()
                    break
            if selected == 0:
                print("unselected,try again!")
        else:
            print("error,try again!")

    elif mode == '3':
        print("Full-time Employee")
        for j in range(1, i):
            eval('f_employee' + str(j)).print_info()
            eval('f_employee' + str(j)).print_salary()
        print("Part-time Employee")
        for j in range(1, f):
            eval('p_employee' + str(j)).print_info()
            eval('p_employee' + str(j)).print_salary()

    elif mode == '4':
        exit()

    else:
        print("error,try again!")

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值