m1-工資管理系統

#!/usr/local/bin/python3
# -*- coding:utf-8 -*-
# AUTHOR:Howard hao
import os,shutil
print('歡迎進入工資管理系統')
def help_show():
    print("1.查詢員工工資\n2.修改員工工資\n3.增加新員工記錄\n4.退出")
    print("鍵入數字進入對應菜單,二級菜單下鍵入空值返回上一層菜單。")
while True:
    help_show()
    Num = input("Your input is:")
    if Num == '1':
        print('進入工資查詢界面')
        while True:
            Name = input('你要查詢的員工是:')
            with open('info.txt', 'r') as f1:
                f2 = f1.read()
                if not Name in f2:
                    print('該員工不存在')
                    continue
            if Name.strip() == '':
                break
            with open('info.txt','r') as f:
                for i in f:
                    if Name in i:
                        I = i.split()
                        salary = I[1]
                        print('%s的工資爲:%s' %(Name,salary))
    elif Num == '2':
        print('進入工資修改界面')
        while True:
            Name = input('你要修改工資的員工是:')
            with open('info.txt', 'r') as f1:
                f2 = f1.read()
                if not Name in f2:
                    print('該員工不存在')
                    continue
            if Name.strip() == '':
                break
            salary = input('想修改成:')
            if Name.strip() == '':
                break
            f = open('info.txt', 'r')
            f1 = open('info_update','w')
            for i in f:
                if Name in i:
                    i = '%s %s\n' %(Name,salary)
                f1.write(i)
            BASE_DIR = os.path.dirname(__file__)
            f.close()
            f1.close()
            shutil.copy('info_update','info.txt')
    elif Num == '3':
        print('進入增加新記錄界面')
        while True:
            Name = input('新員工名字:')
            if Name.strip() == '':
                break
            salary = input('新員工薪水:')
            if Name.strip() == '':
                break
            with open('info.txt', 'a') as f:
                i = '\n%s %s' % (Name,salary)
                f.write(i)
    elif Num == '4':
        exit()
    elif Num.strip() == '':
        exit()


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章