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 ")