使用Python3怎么實(shí)現(xiàn)一個(gè)工資管理系統(tǒng)?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
創(chuàng)新互聯(lián)公司:公司2013年成立為各行業(yè)開拓出企業(yè)自己的“網(wǎng)站建設(shè)”服務(wù),為上千家公司企業(yè)提供了專業(yè)的網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站、網(wǎng)頁設(shè)計(jì)和網(wǎng)站推廣服務(wù), 按需定制設(shè)計(jì)由設(shè)計(jì)師親自精心設(shè)計(jì),設(shè)計(jì)的效果完全按照客戶的要求,并適當(dāng)?shù)奶岢龊侠淼慕ㄗh,擁有的視覺效果,策劃師分析客戶的同行競爭對(duì)手,根據(jù)客戶的實(shí)際情況給出合理的網(wǎng)站構(gòu)架,制作客戶同行業(yè)具有領(lǐng)先地位的。工資管理系統(tǒng)要求:
1. 查詢員工工資
2. 修改員工工資
3. 增加新員工記錄
4. 退出
執(zhí)行代碼:
#!/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("請(qǐng)選擇你的服務(wù)>>:") 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("請(qǐng)輸入要查詢的員工姓名:").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("請(qǐng)輸入要修改的員工姓:").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("請(qǐng)輸入修改的新員工姓名和工資,用空格分割:").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("請(qǐng)輸入要增加的員工姓名和工資,用空格分割:").strip().split() except ValueError: print("\033[31;1m輸入的參數(shù)不夠!\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參數(shù)類型不對(duì)!\033[0m\n") elif serial_number == 4: print("\033[31;1m謝謝使用,下次再見!\033[0m\n") exit() else: print("\033[31;1m請(qǐng)輸入正確的序號(hào)!\033[0m\n") else: print("\033[31;1m輸入的不是整數(shù)!\033[0m\n")
info.txt
name salary
Alex 100000
Rain 80000
Egon 50000
Yuan 30000
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司的支持。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、網(wǎng)站設(shè)計(jì)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。