定义一个学生成绩信息类,包括姓名、成绩。定义一个成绩打印方法,打印成绩(60一下为补考,60以上 为及格,70以上为中等,80以上为良好,90以上为优秀)
时间: 2024-05-01 12:22:18 浏览: 16
以下是一个Python实现的学生成绩信息类及成绩打印方法:
```python
class Student:
def __init__(self, name, score):
self.name = name
self.score = score
def print_score(self):
if self.score < 60:
print('{}的成绩为{},需要补考。'.format(self.name, self.score))
elif self.score < 70:
print('{}的成绩为{},及格。'.format(self.name, self.score))
elif self.score < 80:
print('{}的成绩为{},中等。'.format(self.name, self.score))
elif self.score < 90:
print('{}的成绩为{},良好。'.format(self.name, self.score))
else:
print('{}的成绩为{},优秀。'.format(self.name, self.score))
```
以上代码中,`Student` 类包括了 `name` 和 `score` 两个属性,分别表示学生的姓名和成绩。`print_score` 方法用于打印学生的成绩,根据分数的不同输出不同的评价。使用示例如下:
```python
# 创建一个学生对象
student = Student('张三', 85)
# 打印该学生的成绩
student.print_score() # 输出:张三的成绩为85,良好。
```
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![sb3](https://img-home.csdnimg.cn/images/20210720083646.png)