Python3实现的简单工资管理系统示例

秋天,大雁南飞,草木枯荣,掉落下的依依不舍的树叶随着瑟瑟的秋风飞动。尽管田园一片荒凉,但金灿灿的干草已覆盖了整个大地,几颗松树笔直的立在大地上,天空是多么广阔,多么蔚蓝!地是多么浩瀚,多么无边!天和地连在了一起,已分不清地平线在哪里,秋天的原野拥抱着蓝天,广阔的蓝天拥抱着田野!

本文实例讲述了Python3实现的简单工资管理系统。分享给大家供大家参考,具体如下:

工资管理系统要求:

1. 查询员工工资
2. 修改员工工资
3. 增加新员工记录
4. 退出

执行代码:

#!/usr/bin/env python3
# Author:Robert
# --*-- coding: utf-8 --*--
def file_test():
  with open("info.txt",'r',encoding="utf-8") as f:
    file = list(f)
    return file
def server():
  for i in range(1):
    print("1.查询员工工资\n2.修改员工工资\n3.增加新员工记录\n4.退出")
    return i
loginSucces = False
while True:
    i = server()
    serial_number = input("请选择你的服务>>:")
    if serial_number.isdigit():
      serial_number = int(serial_number)
      file = file_test()
      if serial_number < 5 and serial_number >= 0:
        if serial_number == 1:
          name = input("请输入要查询的员工姓名:").strip()
          for i in file:
            file = i.strip().split()
            if name in file:
              break
          for i in file:
            if name in file:
              name_sum = file[1]
              print("\033[32;1m%s的工资是:%s\033[0m\n"%(name,name_sum))
              break
          else:
            print("\033[31;1m没有此用户!\033[0m\n")
        elif serial_number == 2:
          name_old = input("请输入要修改的员工姓:").strip()
          for ii in file:
            file = ii.strip().split()
            if name_old in file:
              print(file)
              sum_old = file[1]
              name_alter,sum_alter = input("请输入修改的新员工姓名和工资,用空格分割:").strip().split()
              with open("info.txt","r",encoding="utf-8") as f:
                lines = f.readlines()
              with open("info.txt","w",encoding="utf-8") as f_a:
                for line in lines:
                  if name_old in line:
                    line = line.replace(name_old,name_alter)
                  f_a.write(line)
                f_a.close()
                with open("info.txt", "r", encoding="utf-8") as f:
                  lines = f.readlines()
                with open("info.txt", "w", encoding="utf-8") as f_b:
                  for line in lines:
                    if name_alter in line:
                      line = line.replace(sum_old,sum_alter)
                    f_b.write(line)
                  f_b.close()
                  print("修改成功")
                  break
                  if loginSucces == True: break
          else:
            print("\033[31;1m没有此用户!\033[0m\n")
        elif serial_number == 3:
          try:
            name_new, sum_new = input("请输入要增加的员工姓名和工资,用空格分割:").strip().split()
          except ValueError:
            print("\033[31;1m输入的参数不够!\033[0m\n")
          else:
            if name_new.isalpha() and sum_new.isdigit():
              for ii in file:
                file = ii.strip().split()
                if name_new not in file:
                  with open("info.txt", "a+", encoding="utf-8") as f_c:
                    f_c.write("\n%s %s"%(name_new,sum_new))
                  print("增加成功")
                  break
                  if loginSucces == True: break
            else:
              print("\033[31;1m参数类型不对!\033[0m\n")
        elif serial_number == 4:
          print("\033[31;1m谢谢使用,下次再见!\033[0m\n")
          exit()
      else:
        print("\033[31;1m请输入正确的序号!\033[0m\n")
    else:
      print("\033[31;1m输入的不是整数!\033[0m\n")

info.txt

name salary
Alex 100000
Rain 80000
Egon 50000
Yuan 30000

希望本文所述对大家Python程序设计有所帮助。

以上就是Python3实现的简单工资管理系统示例。昨日梦见了犹豫,达到理想不太易,即使有信心,斗志却抑制!更多关于Python3实现的简单工资管理系统示例请关注haodaima.com其它相关文章!