You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

279 lines
8.9 KiB

11 months ago
import os.path
filename = 'students.txt'
def main():
while True:
menu()
choice = int(input('<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>0~7<><37>'))
if choice in [0, 1, 2, 3, 4, 5, 6, 7]:
if choice == 0:
answer = input('<EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>y/n')
if answer == 'y' or answer == 'Y':
print("<EFBFBD><EFBFBD>ӭ<EFBFBD>ٴ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD>")
break
else:
continue
elif choice == 1:
insert()
elif choice == 2:
search()
elif choice == 3:
delete()
elif choice == 4:
modify()
elif choice == 5:
sort()
elif choice == 6:
total()
elif choice == 7:
show()
input()
def menu():
print('=======================================')
print('==========<3D><><EFBFBD>ϴ<EFBFBD>ѧѧ<D1A7><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>ϵͳ==========')
print('=======================================')
print('\t\t\t1.¼<><C2BC><EFBFBD><EFBFBD>Ϣ')
print('\t\t\t2.<2E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ')
print('\t\t\t3.ɾ<><C9BE><EFBFBD><EFBFBD>Ϣ')
print('\t\t\t4.<2E>޸<EFBFBD><DEB8><EFBFBD>Ϣ')
print('\t\t\t5.<2E>Գɼ<D4B3><C9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
print('\t\t\t6.ͳ<><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>')
print('\t\t\t7.<2E><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ')
print('\t\t\t0.<2E>˳<EFBFBD>')
print('======================================')
def insert():
student_list = []
while True:
id = input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD>")
if not id:
break
name = input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
if not name:
break
try:
english = int(input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӣ<EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD>"))
python = int(input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>python<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD>"))
java = int(input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Java<EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD>"))
except:
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
# <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>
student = {'id': id, 'name': name, 'english': english, 'python': python, 'java': java}
# <20><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ӵ<EFBFBD><D3B5>б<EFBFBD><D0B1><EFBFBD>
student_list.append(student)
answer = input("<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>y/n?")
if answer == 'y':
continue
else:
break
# <20><><EFBFBD><EFBFBD>save<76><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
save(student_list)
print("<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>")
def save(lst):
try:
stu_txt = open(filename, 'a', encoding='utf-8')
except:
stu_txt = open(filename, 'w', encoding='utf-8')
for item in lst:
stu_txt.write(str(item) + '\n')
stu_txt.close()
def search():
student_query = []
while True:
id = ''
name = ''
if os.path.exists(filename):
mode = input("<EFBFBD><EFBFBD>ѧ<EFBFBD>Ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD>밴1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>밴2<EFBFBD><EFBFBD>")
if mode == '1':
id = input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD>")
elif mode == '2':
name = input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
else:
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
search()
with open(filename, 'r', encoding='utf-8') as file:
student = file.readlines()
for item in student:
d = dict(eval(item))
if id != '':
if d['id'] == id:
student_query.append(d)
elif name != '':
if d['name'] == name:
student_query.append(d)
show_query(student_query)
# <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
student_query.clear()
answer = input("<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>y/n")
if answer == 'y':
continue
else:
break
else:
print("<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ")
return
def show_query(lst):
if len(lst) == 0:
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ")
return
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ʽ
format_title = '{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}'
print(format_title.format('ID', '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>', 'Ӣ<EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>', 'python<EFBFBD>ɼ<EFBFBD>', 'Java<EFBFBD>ɼ<EFBFBD>', '<EFBFBD>ܳɼ<EFBFBD>'))
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ʽ
format_data = '{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}'
for item in lst:
print(format_data.format(item.get('id'),
item.get('name'),
item.get('english'),
item.get('english'),
item.get('java'),
int( item.get('english')) + int( item.get('english')) + int( item.get('java'))
))
def delete():
while True:
student_id = input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD>")
if student_id != '':
if os.path.exists(filename):
with open(filename,'r',encoding='utf-8') as file:
student_old = file.readlines()
else:
student_old = []
flag = False
if student_old: # <20><><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD> False<73><65><EFBFBD>ǿ<EFBFBD><C7BF>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>True
with open(filename,'w',encoding='utf-8') as wfile:
# ֻ<><D6BB><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EBA1A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>Ѵ<EFBFBD><D1B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>ͷ<EFBFBD><CDB7>ʼ<EFBFBD><EFBFBD><E0BCAD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD>ݻᱻɾ<E1B1BB><C9BE>
d = {}
for item in student_old:
d = dict(eval(item)) # <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>ֵ<EFBFBD>
if d['id'] != student_id:
wfile.write(str(d)+'\n')
else:
flag = True
if flag:
print(f'idΪ{student_id}<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ѱ<EFBFBD>ɾ<EFBFBD><EFBFBD>')
else:
print(f'û<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>ѧ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>Ϊ{student_id}<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>')
else:
print("<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ")
break
show()
answer = input("<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>y/n")
if answer == 'y':
continue
else:
break
def modify():
show()
if os.path.exists(filename):
with open(filename, 'r', encoding='utf-8') as file:
student_old = file.readlines()
else:
return
student_id = input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD>")
with open(filename, 'w', encoding='utf-8') as wfile:
for item in student_old:
d = {}
d = dict(eval(item))
if d['id'] == student_id:
print("<EFBFBD>Ѿ<EFBFBD><EFBFBD>ҵ<EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ")
while True:
try:
d['name'] = input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
d['english'] = input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӣ<EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>")
d['python'] = input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>python<EFBFBD>ɼ<EFBFBD>")
d['java'] = input("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Java<EFBFBD>ɼ<EFBFBD>")
except:
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
else:
break
wfile.write(str(d) + '\n')
print("<EFBFBD>޸ijɹ<EFBFBD>")
else:
wfile.write(str(d)+'\n')
answer = input("<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>y/n")
if answer == 'y':
modify()
else:
return
def sort():
show()
if os.path.exists(filename):
with open(filename, 'r', encoding= 'utf-8') as file:
students = file.readlines()
students_new = []
for item in students:
d = dict(eval(item))
students_new.append(d)
else:
return
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
asc_or_desc = input("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <20><><EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD> 1<><31>")
if asc_or_desc == '0':
asc_or_desc_bool = False
elif asc_or_desc == '1':
asc_or_desc_bool = True
else:
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
sort()
mode = input("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ(1.Ӣ<><D3A2> 2.python 3.Java 4.<2E>ܳɼ<DCB3>)<29><>")
if mode == '1':
students_new.sort(key=lambda x : int(x['english']), reverse=asc_or_desc_bool)
# x <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>students_new<65>е<EFBFBD><D0B5><EFBFBD>
elif mode == '2':
students_new.sort(key=lambda x: int(x['python']), reverse=asc_or_desc_bool)
elif mode == '3':
students_new.sort(key=lambda x: int(x['java']), reverse=asc_or_desc_bool)
elif mode == '4':
students_new.sort(key=lambda x: int(x['english']) + int(x['python']) + int(x['java']), reverse=asc_or_desc_bool)
else:
print("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
show_query(students_new)
def total():
if os.path.exists(filename):
with open(filename, 'r', encoding='utf-8') as file:
students = file.readlines()
if students:
print(f"<EFBFBD>ܹ<EFBFBD><EFBFBD><EFBFBD>{len(students)}<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>")
else:
print("<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ")
else:
print("<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ")
def show():
student_query = []
if os.path.exists(filename):
with open(filename, 'r', encoding='utf-8') as file:
student = file.readlines()
for item in student:
d = dict(eval(item))
student_query.append(d)
show_query(student_query)
# <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
student_query.clear()
else:
print("<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ")
return
if __name__ == '__main__':
main()