python制定成绩单
时间: 2024-10-17 18:02:25 浏览: 15
学生信息及成绩管理系统(Python+Sqlite)数据库版
在Python中,你可以创建一个简单的函数或类来模拟制作成绩单的过程。这通常涉及定义一个数据结构,比如字典或类实例,来存储学生的信息以及他们的成绩。这里是一个基本的例子:
```python
class Student:
def __init__(self, name, id, grades):
self.name = name
self.id = id
self.grades = grades
def create_report(student_list):
report = {}
for student in student_list:
report[student.id] = {
'Name': student.name,
'Grades': {subject: grade for subject, grade in zip(['Math', 'English', 'Science'], student.grades)}
}
return report
# 创建学生对象
student1 = Student('张三', 1001, [90, 85, 95])
student2 = Student('李四', 1002, [88, 92, 90])
# 制作成绩单
students = [student1, student2]
report = create_report(students)
# 打印报告
for student_id, details in report.items():
print(f"学生ID: {student_id}")
print(f"姓名: {details['Name']}")
print(f"成绩:")
for subject, grade in details['Grades'].items():
print(f"{subject}: {grade}")
阅读全文