学生类,学号,姓名,年龄,语文成绩,数学成绩,英语成绩三个学生计算三个学生的平均分
时间: 2023-12-13 13:19:01 浏览: 139
好的,根据您的要求,我来为您编写代码:
```python
# 定义学生类
class Student:
def __init__(self, stu_num, name, age, chinese_score, math_score, english_score):
self.stu_num = stu_num
self.name = name
self.age = age
self.chinese_score = chinese_score
self.math_score = math_score
self.english_score = english_score
# 定义三个学生对象
stu1 = Student('001', '张三', 18, 90, 85, 95)
stu2 = Student('002', '李四', 19, 85, 88, 92)
stu3 = Student('003', '王五', 20, 92, 90, 94)
# 计算三个学生的平均分
chinese_avg = (stu1.chinese_score + stu2.chinese_score + stu3.chinese_score) / 3
math_avg = (stu1.math_score + stu2.math_score + stu3.math_score) / 3
english_avg = (stu1.english_score + stu2.english_score + stu3.english_score) / 3
# 输出平均分
print('语文平均分:%.2f' % chinese_avg)
print('数学平均分:%.2f' % math_avg)
print('英语平均分:%.2f' % english_avg)
```
以上代码输出结果为:
```
语文平均分:89.00
数学平均分:87.67
英语平均分:93.67
```
希望能够帮到您!如果您还有其他问题,可以随时问我哦~
阅读全文