zoukankan      html  css  js  c++  java
  • 简单的工资管理系统小程序,只是练手

    需求如下:

    工资管理系统
    aaa 100000
    bbb 80000
    ccc 50000
    ddd 30000
    -----以上是info.txt文件-----
    实现效果:
    从info.txt文件中读取员工及其工资信息,最后将修改或增加的员工工资信息
    也写入原info.txt文件。
    效果演示:
    1. 查询员工工资
    2. 修改员工工资
    3. 增加新员工记录
    4. 退出
      1 #!/usr/bin/env python
      2 #-*- coding:utf-8 -*-
      3 # @Time    : 2017/9/21 15:19
      4 # @Author  : lichuan
      5 # @File    : salary.py
      6 
      7 import  os
      8 
     25 
     26 def select(read,write):
     27     i=input("please input the employee name:").strip()
     28     for line in read:
     29         if i == line.split()[0]:
     30             print("%s的工资是:%s" % (line.split()[0],line.split()[1]))
     31             return
     32     print("输入错误,请重试!")
     33     read.seek(0)
     34     select(read, write)
     35 
     36 def modify(read,write):
     37     # import os
     38     FLAG_TAG=True
     39     m=input("请输入要修改的员工姓名和工资,以空格分隔").strip().split()
     40     if len(m) !=2:
     41         print("输入错误,请重试,以空格分隔!")
     42         modify(read,write)
     43         return
     44     for i in read:
     45         if i.split()[0] == m[0] and m[1].isdigit():
     46             FLAG_TAG=False
     47             i = "%s %s\n" % (m[0], m[1])
     48         write.write(i)
     49     if FLAG_TAG:
     50         print("输入错误,请重试!")
     51         read.seek(0)
     52         write.seek(0)
     53         modify(read,write)
     54     else:
     55         read.close()
     56         write.close()
     57         os.remove("info.txt")
     58         os.rename(".swap", "info.txt")
     59 
     60 
     61 
     62 def add(read,write):
     63     # import os
     64     a=input("请输入员工姓名和工资,以空格分隔").strip().split()
     65     if len(a) !=2:
     66         print("输入错误,请重试,以空格分隔!")
     67         add(read,write)
     68         return
     69 
     70     for i in read:
     71         if i.split()[0] == a[0]:
     72             print("用户已存在,请重新添加新用户!")
     73             read.seek(0)
     74             write.seek(0)
     75             add(read,write)
     76             return
     77         write.write(i)
     78     write.write("\n%s %s" %(a[0],a[1]))
     79     read.close()
     80     write.close()
     81     os.remove("info.txt")
     82     os.rename(".swap","info.txt")
     83 
     84 
     85 
     86 def out(read,write):
     87 
     88     print("再见!")
     89     # FLAG_TAG=False
     90 
     91 item={
     92     1:"查询员工工资",
     93     2:"修改员工工资",
     94     3:"增加新员工记录",
     95     4:"退出"
     96       }
     97 
     98 fun={
     99     1:select,
    100     2:modify,
    101     3:add,
    102     4:out
    103 }
    104 
    105 FLAG_TAG=True
    106 
    107 while FLAG_TAG:
    108     for i in range(1,5):
    109         print("%d, %s" %(i,item[i]))
    110     choice=input("请选择:").strip()
    111     with open('info.txt','r',encoding="utf-8") as r_read,open('.swap','w',encoding="utf-8") as r_write:
    112         if choice.isdigit() and int(choice) >=1 and int(choice)<4:
    113             choice=int(choice)
    114             fun[choice](r_read,r_write)
    115             continue
    116         elif choice.isdigit() and int(choice) == 4:
    117             FLAG_TAG=False
    118             fun[int(choice)](r_read,r_write)
    119             break
    120         else:
    121             print("wrong input,try again!")
    122             continue
    123     FLAG_TAG=False
  • 相关阅读:
    .NET : 单元测试到底给我们带来什么
    .NET : 如何将16进制颜色代码转换为十进制
    LINQ : 谈谈LINQ TO SQL中的直接加载和延迟加载
    .NET : 单元测试的几个Attribute介绍
    .NET : 在单元测试中使用外部文件作为数据源
    再来谈谈json
    .NET : 关于图片格式的问题
    VSTS : 比较性能基准
    .NET : 如何将大文件写入到数据库中
    LINQ : 如何在JOIN或者GROUP BY的时候使用复合键
  • 原文地址:https://www.cnblogs.com/litzhiai/p/7573583.html
Copyright © 2011-2022 走看看