作业三以及考试
工資管理系統(tǒng)
Alex 100000
Rain 80000
Egon 50000
Yuan 30000
-----以上是info.txt文件-----
實現(xiàn)效果:
從info.txt文件中讀取員工及其工資信息,最后將修改或增加的員工工資信息也寫入原info.txt文件。
效果演示:
1. 查詢員工工資
2. 修改員工工資
3. 增加新員工記錄
4. 退出
>>:1
請輸入要查詢的員工姓名(例如:Alex):Alex
Alex的工資是:100000。
1. 查詢員工工資
2. 修改員工工資
3. 增加新員工記錄
4. 退出
>>:2
請輸入要修改的員工姓名和工資,用空格分隔(例如:Alex 10):Alex 10
修改成功!
1. 查詢員工工資
2. 修改員工工資
3. 增加新員工記錄
4. 退出
>>:3
請輸入要增加的員工姓名和工資,共空格分割(例如:Eric 100000):Eric 100000
增加成功!
1. 查詢員工工資
2. 修改員工工資
3. 增加新員工記錄
4. 退出
>>:4
再見!
?
info.txt
Alex 100000
Rain 80000
Egon 50000
Yuan 30000
lzd 55555
?
# !/usr/bin/env python # -*- coding:utf-8 -*- # Author:lzd user=dict()with open('info.txt','r',encoding='utf-8') as f:for line in f:userlist=line.split()key=userlist[0].strip()salary=userlist[1].strip()user[key]=salary#print(user) xunhuanbiaozhi=True while xunhuanbiaozhi:#print("當前所有人的姓名以及工資如下:")# for list in user:# print(list,user[list])print("1、查詢")print("2、新增")print("3、修改")print("4、刪除")print("5、退出")select=input("選擇您需要接下來的操作:")if select == '1' or select=='查詢':selecta=input('請輸入員工的姓名:')if selecta in user:print("%s的當前工資為%s"%(selecta,user[selecta]))else:print("您輸入的員工姓名%s在數(shù)據(jù)庫里不存在!請重新選擇~"%selecta)elif select == '2' or select=='新增':while True:tempselectb = input('請輸入要新增的員工姓名和工資,用一個空格分隔(例如:Alex 10)').split()#print(tempselectb)if len(tempselectb)!=2:print("你輸入格式有誤~!請重新輸入")breakselectb=tempselectb[0].strip()salaryb=tempselectb[1].strip()if selectb in user:print("您輸入的員工姓名已經(jīng)存在了!請重新選擇~")continueelse:if salaryb.isdigit():user[selectb]=salarybprint("新增員工成功!")breakelse:print("工資應(yīng)該是數(shù)字哦。你輸入的是啥?")continueelif select == '3' or select=='修改':while True:tempselectc=input('請輸入要修改的員工姓名和工資,用空格分割(例如:Eric 100000)').split()if len(tempselectc) != 2:print("你輸入格式有誤~!請重新輸入")breakselectc = tempselectc[0].strip()salaryc = tempselectc[1].strip()if selectc in user:if salaryc.isdigit():user[selectc] = salarycprint("修改員工工資成功!")breakelse:print("工資應(yīng)該是數(shù)字哦。你輸入的是啥?")continueelse:print("你確定你是要修改%s的工資,數(shù)據(jù)庫里沒這個人呀?!請重新選擇~"%selectc)elif select == '4' or select=='刪除':selectd=input("請輸入你想要刪除的人名:")if selectd in user:user.pop(selectd)print("刪除%s成功!"%selectd)else:print("你確定你是要刪除%s,數(shù)據(jù)庫里沒這個人呀?!請重新選擇~"%selectd)elif select == '5' or select == '退出':xunhuanbiaozhi = Falseelse:print("請輸入數(shù)字1-5或者直接打中文,請重新選擇~")#print(user) with open('info.txt','w',encoding='utf-8') as f:for data in user:f.write(data+' '+user[data]+'\n')print("再見~!")?
轉(zhuǎn)載于:https://www.cnblogs.com/itfat/p/7413445.html
總結(jié)
- 上一篇: _variant_t和_bstr_t
- 下一篇: 裁剪区域