Wage System-operations on exercise files (ADD, modify, and query) and wages --

Source: Internet
Author: User

Wage System-operations on exercise files (ADD, modify, and query) and wages --

'''
1. saved in a dictionary
2. No exception capture is performed.
3. You must create an info file in the following format:
{'Name': 'xiaoli', 'salary ': 9990}
{'Name': 'xiaowang ', 'salary': 8000}
'''
Def memu ():
Print ("1. querying employee salaries ")
Print ("2. Modify employee salary ")
Print ("3. Add new employee records ")
Print ("4. Quit ")

Def find_wages (_ name ):
With open ("info", "r", encoding = "UTF-8") as f:
Flag = 0
For line in f:
If line. strip () = "":
Continue
Line = eval (line)
If line ["name"] = _ name:
Print ("\ 033 [31; 1 m % s salary is % d \ 033 [0 m" % (line ["name"], line ["salary"]) + '\ n ')
Flag = 1
If flag = 0:
Print ("\ 033 [36; 1 m employee does not include % s \ 033 [0 m" % _ name)

Def modify_wages (_ name ):
List = []
With open ("info", "r", encoding = "UTF-8") as f:
For line in f:
Flag = 0
If line. strip () = "":
Continue
Line = eval (line)
If line ["name"] = _ name:
Salary = input ("Enter the modified salary >>> ")
If salary. isdigit ():
Salary = int (salary)
Else:
Print ("\ 033 [36; 1 m input error \ 033 [0 m ")
Line ["salary"] = salary
Print ("\ 033 [32; the salary after 1 m % s is % d \ 033 [0 m" % (line ["name"], line ["salary"]) + '\ n ')
Else:
If flag = 0:
Print ("\ 033 [36; 1 m employee does not include % s \ 033 [0 m" % _ name)
Flag = 1
List. append (line)
With open ("info", "w", encoding = "UTF-8") as f1:
For temp in list:
F1.write (str (temp) + '\ n ')

Def add_wages ():
Dict = {}
Name = input ("enter the name of the employee you want to add> ")
Salary = input ("Enter the new employee's salary >>> ")
If salary. isdigit ():
Salary = int (salary)
Else:
Print ("\ 033 [36; 1 m input error \ 033 [0 m ")
Dict ["name"] = name
Dict ["salary"] = salary
Print ("\ 033 [35; 1 m new employee % s salary is % d \ 033 [0 m" % (dict ["name"], dict ["salary"]) + '\ n ')
With open ("info", "a", encoding = "UTF-8") as f:
F. write (str (dict) + '\ n ')

While True:
Memu ()
Choose = input ("Enter the operation you want to perform >>> ")
If choose. isdigit ():
Choose = int (choose)
Else:
Print ("\ 033 [36; 1 m input error \ 033 [0 m ")
Continue
If choose = 1:
Name = input ("enter the name of the employee to be queried >>> ")
Find_wages (name)
Elif choose = 2:
Name = input ("enter the name of the employee to be modified >>> ")
Modify_wages (name)
Elif choose = 3:
Add_wages ()
Elif choose = 4:
Exit ()
Else:
Print ("\ 033 [36; 1 m input error \ 033 [0 m ")

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.