python實例_工資管理系統
阿新 • • 發佈:2017-07-16
break http lis with utf 服務 def span value
一,作者介紹
吳海東:My Blog:http://www.cnblogs.com/whd-67270
二,程序說明
1. 查詢員工工資
2. 修改員工工資
3. 增加新員工記錄
4. 退出
三,程序前準備
創建一個存放員工信息的文件,裏面記錄員工的姓名和工資
四,程序腳本
def file_test(): with open("yuangong.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 < 4 andserial_number >= 0: if serial_number == 1: name = input("請輸入要查詢的員工姓名:").strip() for i in file: file = i.strip().split() if name in file: break fori 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("yuangong.txt","r",encoding="utf-8") as f: lines = f.readlines() with open("yuangong.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("yuangong.txt", "r", encoding="utf-8") as f: lines = f.readlines() with open("yuangong.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) 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("yuangong.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: exit() else: print("\033[31;1m請輸入正確的序號!\033[0m\n") else: print("\033[31;1m輸入的不是整數!\033[0m\n")
五,執行演示
python實例_工資管理系統