Python 学生成绩管理系统 将学生对象存入列表中,并按成绩对学生进行排序,并获取成绩最高和成绩最低的学生信息,并将最高分和最低分的学生从列表删除,最后再对列表进行拷贝,对拷贝的列表进行翻转输出
实验题目:学生成绩管理将学生对象存入列表中,并按成绩对学生进行排序,并获取成绩最高和成绩最低的学生信息,并将最高分和最低分的学生从列表删除,最后再对列表进行拷贝,对拷贝的列表进行翻转输出。源代码如下:stu_list = []class student:#学号 姓名 成绩def __init__(self,sno,name,score):self.sno = snos...
·
|
实验题目:学生成绩管理 将学生对象存入列表中,并按成绩对学生进行排序,并获取成绩最高和成绩最低的学生信息,并将最高分和最低分的学生从列表删除,最后再对列表进行拷贝,对拷贝的列表进行翻转输出。 源代码如下: stu_list = []
class student:
#学号 姓名 成绩
def __init__(self,sno,name,score):
self.sno = sno
self.name = name
self.score = score
def info(self):
print(f'学号:{self.sno}, 姓名:{self.name}, 成绩:{self.score}')
s1 = student('001','AAA',100)
s2 = student('002','BBB',89)
s3 = student('003','CCC',76)
s4 = student('004','DDD',95)
s5 = student('005','EEE',59)
s6 = student('006','FFF',90)
stu_list.append(s1)
stu_list.append(s2)
stu_list.append(s3)
stu_list.append(s4)
stu_list.append(s5)
stu_list.append(s6)
print('学生列表中学生信息为:')
for stu in stu_list:
stu.info()
print('*'*30)
#按成绩升序排序后得到的新的学生列表
print('按成绩升序排序后得到的新的学生列表:')
stu_list1 = sorted(stu_list,key=lambda stu:stu.score)
for stu in stu_list1:
stu.info()
print('*'*30)
print('成绩最好的学生信息为:')
stu_list1[len(stu_list1)-1].info()
print('成绩最低的学生信息:')
stu_list1[0].info()
print('*'*30)
#从学生列表中移除成绩最高和最低的学生的信息
stu_list.remove(stu_list1[0])
stu_list.remove(stu_list1[len(stu_list1)-1])
print('移除成绩最高和最低的学生后学生列表中学生信息:')
for stu in stu_list:
stu.info()
print('*'*30)
#深拷贝
stu_list2 = copy.deepcopy(stu_list)
print('进行深拷贝后翻转输出学生信息:')
for i in range(len(stu_list2)-1,-1,-1):
stu_list2[i].info()
运行结果截图:
|
更多推荐





所有评论(0)