Exercise 1:
stu_num = int(input("Please define the number of students:"))
cour_num = int(input("Please define the number of courses:"))
cour_name = []
stu_all = []#For storing all students
sum_list = []#For storing student's sum of scores
for i in range(cour_num):
course = input("Please input the name of the course "+str(i+1)+":")
cour_name.append(course)
for i in range(stu_num):
student = []
name = input("Please input the name of the student "+str(i+1)+":")
student.append(name)
stu_sum = 0
for j in range(len(cour_name)):
score = int(input("Please input score of "+name+"'s "+cour_name[j]))
stu_sum += score
student.append(score)
student.append(stu_sum)
sum_list.append(stu_sum)
stu_avg = stu_sum/cour_num
student.append(stu_avg)
stu_all.append(student)
for i in range(len(stu_all)-1):
for j in range(len(stu_all)-1 - i):
if sum_list[j] < sum_list[j+1]:
'''swap sum of scores'''
s = sum_list[j]
sum_list[j] = sum_list[j+1]
sum_list[j+1] = s
'''swap student'''
stu1 = stu_all[j]
stu_all[j] = stu_all[j+1]
stu_all[j+1] = stu1
print("Name",end = "\t")
for i in range(len(cour_name)):
print(cour_name[i],end = "\t")
print("Sum Scores\tAverage Score\tRanking")#output a new line
for i in range(len(stu_all)):
for j in range(len(stu_all[i])):
print(stu_all[i][j],end = " \t")
print(i+1)#output a new line
Exercise 2:
stu_num = int(input("Please input the number of students:"))
cour_name = ["French","Math","English"]
stu_all = []#for storing all students
for i in range(stu_num):
student = []
name = input("Please input the name of student "+str(i+1)+":")
student.append(name)
stu_sum = 0
for j in range(len(cour_name)):
score = int(input("Please input the score of "+name+"'s "+cour_name[j]))
stu_sum += score
student.append(score)
student.append(stu_sum)
stu_avg = stu_sum//len(cour_name)
student.append(stu_avg)
stu_all.append(student)
while True:
number = int(input("Please input a number to see the course(1.French 2.Math 3.English 4.Sum Scores 5.Quit)"))
if number == 5:
print("Quit system")
break
elif number == 1 or number == 2 or number == 3 or number == 4:
score_list = []
for i in range(len(stu_all)):
score_list.append(stu_all[i][number])
else:
print("Wrong input, please retry")
continue
'''bubble sort,based on sum scores'''
for i in range(len(stu_all) - 1):
for j in range(len(stu_all) - 1 - i):
if score_list[j] < score_list[j + 1]:
'''swap sum scores'''
s = score_list[j]
score_list[j] = score_list[j + 1]
score_list[j + 1] = s
'''swap student'''
stu1 = stu_all[j]
stu_all[j] = stu_all[j + 1]
stu_all[j + 1] = stu1
'''Travers to output'''
print("Name", end="\t")
for i in range(len(cour_name)):
print(cour_name[i], end="\t")
print("Sum Scores\tAverage Score\tRanking") # output a new line
for i in range(len(stu_all)):
for j in range(len(stu_all[i])):
print(stu_all[i][j], end=" \t")
print(i + 1) # output a new line
[…] for Lists| |____Unit 33 Bubble Sort and Selection Sort| |____Unit 34 Multidimensional Lists| |____Unit 35 Student Performance Management System (Part 1)| |____Unit 36 Student performance management system (Part 2)| |____Unit 37 Student Information […]