Python Instance _ Payroll management System

Source: Internet
Author: User

First, the author introduces

Wu Haidong: My blog:http://www.cnblogs.com/whd-67270

Ii. Description of the procedure

1. Check the employee's salary

2. Revise employee's salary

3. Add new Employee Records

4. Exit

Three, pre-procedure preparation

Create a file that holds employee information that records the employee's name and salary

Four, program script

deffile_test (): With open ("Yuangong.txt",'R', encoding="Utf-8") as F:file=list (f)returnfiledefserver (): forIinchRange (1):        Print("1. Check employee salary \n2. Revise employee \n3. Add new employee record \n4. Exit")        returniloginsucces=False whiletrue:i=server () Serial_number= Input ("Please select your service:")        ifserial_number.isdigit (): Serial_number=Int (serial_number) file=file_test ()ifSerial_number < 4 andSerial_number >=0:ifSerial_number = = 1: Name= Input ("Please enter the name of the employee to be queried:"). Strip () forIinchFile:file=I.strip (). Split ()ifNameinchFile: Break                     forIinchFile:ifNameinchFile:name_sum= File[1]                            Print("\033[32;1m%s's salary is:%s\033[0m\n"%(name,name_sum)) Break                    Else:                        Print("\033[31;1m does not have this user! \033[0m\n")                elifSerial_number = = 2: Name_old= Input ("Please enter the name of the employee you want to modify:"). Strip () forIiinchFile:file=Ii.strip (). Split ()ifName_oldinchFile:Print(file) Sum_old= File[1] Name_alter,sum_alter= Input ("Please enter the revised employee name and salary, separated by a space:"). 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: forLineinchlines:ifName_oldinchLine: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: forLineinchlines:ifName_alterinchLine:line=line.replace (sum_old,sum_alter) f_b.write (line) Print("Modification succeeded")                                     Break                                    ifLoginsucces = = True: Break                    Else:                        Print("\033[31;1m does not have this user! \033[0m\n")                elifSerial_number = = 3:                    Try: name_new, Sum_new= Input ("Please enter the employee name and salary to be added, separated by a space:"). Strip (). Split ()exceptValueError:Print("\033[31;1m input parameters are not enough! \033[0m\n")                    Else:                        ifName_new.isalpha () andsum_new.isdigit (): forIiinchFile:file=Ii.strip (). Split ()ifName_new not inchFile:with Open ("Yuangong.txt","A +", encoding="Utf-8") as F_c:f_c.write ("\n%s%s"%(name_new,sum_new))Print("Increase Success")                                     Break                                    ifLoginsucces = = True: Break                        Else:                            Print("\033[31;1m parameter type is wrong! \033[0m\n")                elifSerial_number = = 4: Exit ()Else:                Print("\033[31;1m Please enter the correct serial number! \033[0m\n")        Else:            Print("\033[31;1m input is not an integer! \033[0m\n")

Five, perform the demo

Python Instance _ Payroll management System

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.