zoukankan      html  css  js  c++  java
  • 简单的工资系统,借鉴了别人的思路,自己补充了下,还有待提高

      1 #!/usr/bin/env python
      2 #-*- coding:utf-8 -*-
      3 #3.0python版本以上运行
      4 import sys
      5 import os
      6 
      7 #将文件变为列表
      8 info_dict = {}
      9 #员工工资
     10 user_dict = {}
     11 #文件修改
     12 def file():
     13     os.remove('user.txt')
     14     os.rename('simple.txt','user.txt')
     15 
     16 
     17 
     18 #所有员工工资
     19 def info():
     20     with open('user.txt','r+') as f:
     21         for i in f:
     22             i = i.strip()
     23             info_dict[i.split(' ')[0]] = i.split(' ')[1]
     24 
     25 #查询员工是否存在
     26 def select():
     27     count = 0
     28     while True:
     29         info()
     30         user_info = input("请输入你的名字,按q则退出---》")
     31         if user_info in info_dict.keys():
     32             print('%s你的工资是:%s' %(user_info,info_dict[user_info]))
     33         elif user_info == 'q':
     34             break
     35         else:
     36             count+=1
     37             print("对不起你输入的名字不存在,你已经尝试%s次" % count)
     38             if count > 3:
     39                 print("对不起你尝试%s次无效用户【%s】,退出!!" %(count,user_info))
     40                 break
     41 #新增员工
     42 def insert():
     43     while True:
     44         info()
     45         user_info = input("请输入需要增加的员工和工资-->").strip()
     46         user_dict[user_info.split(' ')[0]] = user_info.split(' ')[1]
     47         user_list = user_info.split(' ')
     48         if user_info not in info_dict.keys():
     49             user_info = '
    '+user_info
     50             with open('user.txt','a+') as f:
     51                 f.write(user_info)
     52                 print("%s已经添加成功" %user_info[0])
     53                 break
     54         else:
     55             print("%s用户已经存在" %user_info)
     56 
     57 
     58 #修改员工工资
     59 def update():
     60         while True:
     61             info()
     62             user_info = input("请输入你的修改名字---》").strip()
     63             user_new_money = input("请输入你要修改的工资是多少--》")
     64             if user_info in info_dict.keys():
     65                  if user_new_money.isdigit():
     66                 #     user_new_money = int(user_new_money)
     67                     #info_dict[user_info]=user_new_money
     68                     with open('user.txt','r') as f2,open('simple.txt','w') as f3:
     69                         for i in f2:
     70                             i = i.replace(info_dict[user_info],user_new_money)
     71                             f3.write(i)
     72                     print("你的%s员工工资修改为%s" %(user_info,user_new_money))
     73                     file()
     74                     break
     75                  else:
     76                      print("您输入的不是阿拉伯数字,请输入数字")
     77             else:
     78                 print("用户不存在")
     79 
     80 
     81 
     82 a = """
     83 1.查询
     84 2.增加
     85 3.修改
     86 4.退出
     87 """
     88 
     89 all ={
     90     '1':select,
     91     '2':insert,
     92     '3':update,
     93     '4':sys.exit
     94 }
     95 while True:
     96     print(a)
     97     choose = input("请输入你需要的编号--》")
     98     if choose not in all.keys():
     99         continue
    100     all[choose]()
  • 相关阅读:
    Centos7.3防火墙配置
    Centos7使用yum安装MySQL5.6的正确姿势
    Connect C# to MySQL
    ADO.NET操作MySQL数据库
    Mac OS 上 VIM 8.0 安装体验
    WebSocket实战之————Workerman服务器的安装启动
    C语言实现文件复制功能(包括文本文件和二进制文件)
    Gateway/Worker模型 数据库使用示例
    [转]Using the Group Pane to Repeat Page Titles
    [转]学习 WCF (6)--学习调用WCF服务的各种方法
  • 原文地址:https://www.cnblogs.com/jesse-gong/p/7686691.html
Copyright © 2011-2022 走看看