import time
def show_menu():
print("\n\t\t \033[1;31mCHOICE MENU\033[0m")
print('\t\t+--------------------------------------+')
print('\t\t| 1) Add Student Info. |')
print('\t\t| 2) Show All Info. |')
print('\t\t| 3) Delete Info. |')
print('\t\t| 4) Modify Info. |')
print('\t\t| 5) Sort Info. with Score(High to Low)|')
print('\t\t| 6) Sort Info. with Score(Low to High)|')
print('\t\t| 7) Sort Info. with Age(Old to Young) |')
print('\t\t| 8) Sort Info. with Age(Young to Old) |')
print('\t\t| 9) Quit System |')
print('\t\t+--------------------------------------+')
def input_student(lst):
print("\n\t\t\033[1;32mYou are inputting student's info.\033[0m")
item_lst = ['name','age','score']
while True:
info_dict = {}
for i in item_lst:
temp = input("\t\tPlease input student's \033[1;31m%s\033[0m:" % i)
if temp.isnumeric():
temp = int(temp)
info_dict[i] = temp
if info_dict['name'] == '':
return
print()
lst.append(info_dict)
def output_student(lst):
print("\n\t\t\t\033[1;32mStudents' Info. List\033[0m")
item_lst = ['name','age','score']
string1 = ''
string2 = ''
for i in range(len(item_lst)):
string1 += '+' + '-'*10
string2 += '|'+ item_lst[i].center(10)
print('\t\t' + string1 + '+\t\t\t')
print('\t\t' + string2 + '|\t\t\t')
print('\t\t' + string1 + '+\t\t\t')
for info in lst:
string3 = ''
for i in range(len(item_lst)):
string3 += '|' + str(info[item_lst[i]]).center(10)
print('\t\t' + string3 + '|\t\t\t')
print('\t\t' + string1 + '+\t\t\t')
def delete_student(lst):
print("\n\t\t\033[1;32mYou are deleting a student's info.\033[0m")
while True:
name = input("\t\tPlease input the student's \033[1;31mname\033[0m:")
for info in lst:
if info['name'] == name:
lst.remove(info)
print("\t\t\t\033[1;31mDeletion Successful!\033[0m")
conti = input("\t\t\033[1;34mInput 'c' to continue deleting:\033[0m")
if conti != 'c':
print("\t\t\t\033[1;31mDeletion end!\033[0m")
return
else:
break
else:
print("\t\t\033[1;31mCan't Find the Student's Info.\033[0m")
def modify_student(lst):
print("\n\t\t\033[1;32mYou are modifying a student's info.\033[0m")
name = input("\t\tPlease input the student's \033[1;31mname\033[0m:")
for info in lst:
if info['name'] == name:
while True:
temp = input("\t\tPlease input the \033[1;31mitem\033[0m to modify:")
if temp not in info:
print("\t\t\033[1;31mItem Error, Modification Interrupted!\033[0m")
continue
value = input("\t\tThe \033[1;31mnew value\033[0m is:")
info[temp] = value
print("\t\t\t\033[1;31mModification Successful!\033[0m")
conti = input("\t\t\033[1;34mInput 'c' to continue modifying:\033[0m")
if conti != 'c':
print("\t\t\t\033[1;31mModification end!\033[0m")
return
else:
print("\t\t\033[1;31mCan't Find the Student's Info.\033[0m")
def score_sort_high(lst):
new_lst = sorted(lst,key=lambda i: i['score'],reverse=True)
output_student(new_lst)
print("\t\tSorted with score (high to low)")
def score_sort_low(lst):
new_lst = sorted(lst,key=lambda i: i['score'])
output_student(new_lst)
print("\t\tSorted with score (low to high)")
def age_sort_old(lst):
new_lst = sorted(lst,key=lambda i: i['age'],reverse=True)
output_student(new_lst)
print("\t\tSorted with age (old to young)")
def age_sort_young(lst):
new_lst = sorted(lst,key=lambda i: i['age'])
output_student(new_lst)
print("\t\tSorted with age (young to old)")
def main():
lst = []
while True:
time.sleep(2)
show_menu()
n = input("\t\t\033[1;31mYour Choice:\033[0m")
if n == '1':
input_student(lst)
elif n == '2':
output_student(lst)
elif n == '3':
delete_student(lst)
elif n == '4':
modify_student(lst)
elif n == '5':
score_sort_high(lst)
elif n == '6':
score_sort_low(lst)
elif n == '7':
age_sort_old(lst)
elif n == '8':
age_sort_young(lst)
elif n == '9':
return
else:
print("\t\t\t\033[1;31mEROOR INPUT!\033[0m")
if __name__ == '__main__':
main()
student_info.py
最新推荐文章于 2024-09-25 17:40:04 发布