Python Job Payroll management System (third week)

Source: Internet
Author: User

Job Content:

Implementation results:

Read employees and their payroll information from the Info.txt file, and finally write the revised or increased employee payroll information to the original Info.txt file.

Effect Demo:

1. Check the employee's salary

2. Revise employee's salary

3. Add new Employee Records

4. Exit

Ideas:

File reading and writing, read or write data using the Strip and split method, the contents of the file to increase the search

Flowchart: (Pending update)

Code:

#!/usr/bin/env python#-*-coding:utf-8-*-#Author:sean_yao"""Payroll Management System Jobs"""ImportSyswith Open ("Info.txt",'R', encoding="Utf-8") as F:file=list (f) Msg=" "1. Check the employee's salary 2. Revise the employee's salary 3. Add new Employee record 4. Exit" "Exit_flag=False while  notExit_flag:Print(msg) Index_user_choice= Input ('>>:')    ifIndex_user_choice = ='1': With open ("Info.txt",'R', encoding="Utf-8") as F:user_salary=f.readlines () Username= Input ("Please enter the name of the employee to be queried (ex: Alex):")         forUser_lineinchuser_salary: (user,salary)= User_line.strip ('\ n'). Split ()ifUsername = =User:Print('The salary for%s is:%s'%(username,salary))Pass    elifIndex_user_choice = ='2': Old_user= Input ("Enter the employee's name (ex: Alex):"). Strip () forIinchFile:file=I.strip (). Split ()ifOld_userinchfile:old_salary= File[1] New_user,new_salary= Input ("Please enter the employee name and salary after the change, separated by a space (for example: Alex):"). 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: forLineinchlines:ifOld_userinchLine: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: forLineinchlines:ifNew_userinchLine:line=line.replace (old_salary,new_salary) f_b.write (line) F_b.close () Print("Modification succeeded")    elifIndex_user_choice = ='3': F= Open ('Info.txt','r+', encoding='Utf-8') User_salary=f.readlines () new_user_new_salary= Input ("Please enter the name and salary of the employee to be added, split the total space (for example: Eric 100000):") F.write (new_user_new_salary+'\ n') F.close ()elifIndex_user_choice = ='4': Sys.exit ("Goodbye")    Else:        Print('Invalid input operation! ')
View Code

Info.txt File Contents:

Alex 100000800005000030000

Python Job Payroll management System (third week)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.