class Student: def init(self, name, age, cpp_score, math_score): self.name = name self.age = age self.cpp_score = cpp_score self.math_score = math_score

def is_excellent(self):
    return self.cpp_score >= 90 and self.math_score >= 90

students = [Student("Tom", 18, 95, 92), Student("Jerry", 19, 85, 95), Student("Bob", 20, 90, 90)]

excellent_count = 0 for student in students: if student.is_excellent(): excellent_count += 1

print("成绩优秀的学生个数为:", excellent_count)

学生类Student属性有姓名、年龄、C++分数、高等数学分数等请编写代码实现输出成绩优秀的学生的个数成绩优秀指的是C++分数和高等数学分数都大于等于90

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

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