定义函数

def input_score(): num = input("请输入学号:") score1 = float(input("请输入第一门课程成绩:")) score2 = float(input("请输入第二门课程成绩:")) score3 = float(input("请输入第三门课程成绩:")) total_score = score1 + score2 + score3 return num, total_score

主程序

scores = [] for i in range(3): num, total_score = input_score() scores.append((num, total_score)) scores.sort(key=lambda x:x[1], reverse=True) print("按总成绩从大到小排列的学生信息如下:") for s in scores: print("学号:%s,总成绩:%s" % (s[0], s[1]))

编写带有函数的程序要求: 编写一个函数可以输入学生学号以及三门课程成绩编写主程序输入三个学号包括自己的学号和成绩并按总成绩从大到小排列输出。

原文地址: https://www.cveoy.top/t/topic/bS5W 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录