Exercise:
print("====Student Information Management System====")
student_all = []#2 dimentional list, each item in the list is a student information
while True:
number = input("Please pick an operation:\n"\
"1.Add Student\n2.Search Student\n3.Delete Student\n4.Update Student\n5.View All Student\n"
"6.Input Scores\n7.Total Score Ranking\n8.Ranking of One Course\n99.Quit\n")
if number == "99":
print("Abort system.")
break
elif number == "1":
student = []#the list for one student, containing all the information of a student
name = input("Please input student name:")
age = int(input("Please input student age:"))
french = 0
math = 0
english = 0
sum_score = 0
avg_score = 0
student.append(name)
student.append(age)
student.append(french)
student.append(math)
student.append(english)
student.append(sum_score)
student.append(avg_score)
student_all.append(student)#add this student to the student list
print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score")
for i in student:
print(i,end = " \t" )
print()#output a new line
elif number == "2":
name = input("Please input student name you look for:")
for i in range(len(student_all)):
if name in student_all[i]:
print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score")
for j in student_all[i]:
print(j,end = " \t")
print()#output a new line
break
else:
print(name," does not exist.")
elif number == "3":
name = input("Please input the student name to be deleted:")
for i in range(len(student_all)):
if name in student_all[i]:
del student_all[i]
print(name," has been deleted.")
break
else:
print(name," does not exist.")
elif number == "4":
name = input("Please input the student name to be updated:")
for i in range(len(student_all)):
if name in student_all[i]:
name = input("Please input updated name:")
age = int(input("Please input updated age:"))
student_all[i][0] = name
student_all[i][1] = age
print("Update succeeds.")
print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score")
for j in student_all[i]:
print(j,end = " \t")
print()#output a new line
break
else:
print(name," does not exist.")
elif number == "5":
print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score")
for i in range(len(student_all)):
for j in range(len(student_all[i])):
print(student_all[i][j],end = " \t")
print()#output a new line
elif number == "6":
name = input("Please input the student name whose score you will input:")
for i in range(len(student_all)):
if name in student_all[i]:
'''Score input'''
french = int(input("Please input "+name+"'s French score:"))
math = int(input("Please input " + name + "'s Math score:"))
english = int(input("Please input " + name + "'s English score:"))
sum_score = french + math + english
avg_score = sum_score//3
'''Store the score in the student list'''
student_all[i][2] = french
student_all[i][3] = math
student_all[i][4] = english
student_all[i][5] = sum_score
student_all[i][6] = avg_score
print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score")
for i in student_all[i]:
print(i,end = " \t")
print()#output a new line
break
else:
print(name, " does not exist.")
elif number == "7":
score = []#used for storing student's total score
for i in range(len(student_all)):
score.append(student_all[i][5])
all = student_all[:]
'''bubble sort duplicated list based on total scores,'''
for i in range(len(all)-1):
for j in range(len(all)-1-i):
if score[j] < score[j+1]:
s = score[j]
score[j] = score[j+1]
score[j+1] = s
student1 = all[j]
all[j] = all[j+1]
all[j+1] = student1
print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score\tRanking")
for i in range(len(all)):
for j in range(len(all[i])):
print(all[i][j],end = " \t")
print(i+1)#output a new line
elif number == "8":
score = []#used for storing score of one course
course_name = int(input("Please pick one course(1.French 2.Math 3.English)"))
if course_name == 1 or course_name == 2 or course_name == 3:
for i in range(len(student_all)):
score.append(student_all[i][course_name+1])
all = student_all[:]
'''bubble sort the duplicated list based on the score'''
for i in range(len(all)-1):
for j in range(len(all)-1-i):
if score[j] < score[j+1]:
s = score[j]
score[j] = score[j+1]
score[j+1] = s
student1 = all[j]
all[j] = all[j+1]
all[j+1] = student1
print("Name\tAge\tFrench\tMath\tEnglish\tTotal Score\tAverage Score\tRanking")
for i in range(len(all)):
for j in range(len(all[i])):
print(all[i][j],end = " \t")
print(i+1)#output a new line
[…] management system (Part 2)| |____Unit 37 Student Information Management System (Part 1)| |____Unit 38 Student Information Management System (Part 2)| |____Unit 39 Tuple| |____Unit 40 Dictionaries| |____Unit 41 English-Chinese Dictionary| |____Unit […]