while True:
# theme of your home page
print("--------Staff Info. Management System---------")
print("-----1、Adding staff information-----")
print("-----2、Removing staff inormation-----")
print("-----3、Revising staff information-----")
print("-----4、Checking staff information-----")
print("-----5、Checking all staff information-")
print("-----6、EXIT -----")
print("-" * 30)
#input an integer with int
command = int(input("Please choose an option:"))
if command == 1:
# adding staff info.
name = input("Please input staff name:")
worker_id = input("Please input staff ID:")
if (len(worker_id) == 5) and (worker_id.isdigit()):
card_id = input("Please input personal ID:")
if len(card_id) == 8 and (card_id.isdigit() or (card_id[1:7].isdigit() and card_id[1] in "X")):
info_list.append({"Name": name, "Staff ID": worker_id, "ID": card_id})
print("【info】:Added successfully")
print(info_list)
#save dict as txt file
# f=open("data.txt","w")
# for i in info_list:
# for c, b in i.items():
# f.write(str(c)+':'+str(b)+'\n')
# f.close()
else:
print("【ERROR】:the personal ID should be in 8 digits,the first digit canbe x and all the rest must be in numbers")
else:
print("【ERROR】:the staff ID should be in 5 digits")
elif command == 2:
# delete staff info
print(info_list)
name = input("Deletion:Please input the name:")
for i in info_list:
if name in i.values():
del info_list[info_list.index(i)]
print("【info】:Removed successfully")
print(info_list)
break
else:
print("【Error】:No such a person")
elif command == 3:
# Revising staff info
name = input("Revision:Please input the name:")
for i in info_list:
if name in i.values():
worker_id = input("Please input the revised staff ID:")
if (len(worker_id) == 5) and (worker_id.isdigit()):
card_id = input("Please input the personal ID:")
if len(card_id) == 8 and (card_id.isdigit() or (card_id[1:7].isdigit() and card_id[1] in "x")):
info_list[info_list.index(i)] = {"Name": name, "Staff ID": worker_id, "ID": card_id}
print(info_list)
print("【info】:Revised successfully")
break
else:
print("【ERROR】:the personal ID should be in 18 digits,the last digit canbe x and all the rest must be in numbers")
else:
print("【ERROR】:the staff ID should be in 5 digits")
else:
print("【Error】:No such a person")
elif command == 4:
# checking staff info
userName = "yoyo"
passWord = "123456"
userName_input = input("Please input your user name:")
passWord_input = input("Please input your password:")
if (userName == userName_input) and (passWord == passWord_input):
name = input("Search:Please input a name:")
for i in info_list:
if name in i.values():
for k, v in i.items():
print("%s : %s" % (k, v))
break
else:
print("【Error】:No info. for this person")
else:
print("【Error】:Invalid user name or password")
elif command == 5:
#
userName = "yoyo"
passWord = "123456"
userName_input = input("Please input your user name:")
passWord_input = input("Please input your password:")
if (userName == userName_input) and (passWord == passWord_input):
for i in info_list:
for k, v in i.items():