定义一个学生成绩信息类,包括姓名、成绩。定义一个成绩打印方法,打印成绩(60一下为补考,60以上 为及格,70以上为中等,80以上为良好,90以上为优秀)python
时间: 2024-05-06 09:16:45 浏览: 12
以下是一个简单的实现:
```python
class Student:
def __init__(self, name, score):
self.name = name
self.score = score
def print_score(self):
if self.score < 60:
print(f"{self.name}的成绩为{self.score}, 需要补考")
elif self.score < 70:
print(f"{self.name}的成绩为{self.score}, 及格")
elif self.score < 80:
print(f"{self.name}的成绩为{self.score}, 中等")
elif self.score < 90:
print(f"{self.name}的成绩为{self.score}, 良好")
else:
print(f"{self.name}的成绩为{self.score}, 优秀")
```
使用示例:
```python
student1 = Student("张三", 78)
student1.print_score()
student2 = Student("李四", 95)
student2.print_score()
```
输出:
```
张三的成绩为78, 中等
李四的成绩为95, 优秀
```
相关推荐
![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)
![](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)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)