python 工资管理软件_Python作业工资管理系统(第三周)

#!/usr/bin/env python#-*- coding:utf-8 -*-#Author: Sean_Yao

"""工资管理系统作业"""

importsys

with open("info.txt", 'r', encoding="utf-8") as f:

file=list(f)

msg= '''1. 查询员工工资

2. 修改员工工资

3. 增加新员工记录

4. 退出'''exit_flag=Falsewhile notexit_flag:print(msg)

index_user_choice= input('>>:')if index_user_choice == '1':

with open("info.txt", 'r', encoding="utf-8") as f:

user_salary=f.readlines()

username= input("请输入要查询的员工姓名(例如:Alex):")for user_line inuser_salary:

(user,salary)= user_line.strip('\n').split()if username ==user:print('%s 的工资是:%s' %(username,salary))pass

elif index_user_choice == '2':

old_user= input("输入员工姓名(例如:Alex):").strip()for i infile:

file=i.strip().split()if old_user infile:

old_salary= file[1]

new_user,new_salary= input("请输入更改后员工姓名和工资,用空格分隔(例如:Alex 10):").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 inlines:if old_user inline:

line=line.replace(old_user,new_user)

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 inlines:if new_user inline:

line=line.replace(old_salary,new_salary)

f_b.write(line)

f_b.close()print("修改成功")elif index_user_choice == '3':

f= open('info.txt', 'r+', encoding='utf-8')

user_salary=f.readlines()

new_user_new_salary= input("请输入要增加的员工姓名和工资,共空格分割(例如:Eric 100000):")

f.write(new_user_new_salary+ '\n')

f.close()elif index_user_choice == '4':

sys.exit("再见")else:print('输入操作无效!')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值