编写一个函数,完成百分制成绩到等级制成绩的转换。(60以下为“不及格”,60-69为“及格” ,70-79为“中”,80-89为“良好”,90分以上为’优秀’)。
时间: 2024-05-30 16:14:40 浏览: 21
好的,这个问题很简单,下面是代码:
def score_to_grade(score):
if score < 60:
return "不及格"
elif score < 70:
return "及格"
elif score < 80:
return "中"
elif score < 90:
return "良好"
else:
return "优秀"
这个函数可以将百分制成绩转换为等级制成绩,你只需要将成绩作为参数传递给函数,它就会返回相应的等级。
相关问题
python 编写一个函数,完成百分制成绩到等级制成绩的转换。(60以下为“不及格”,60-69为“及格” ,70-79为“中”,80-89为“良好”,90分以上为’优秀’)。
以下是Python代码实现:
```python
def grade(score):
if score >= 90:
return '优秀'
elif score >= 80:
return '良好'
elif score >= 70:
return '中'
elif score >= 60:
return '及格'
else:
return '不及格'
```
调用函数:
```python
print(grade(88)) # 输出:良好
```
本题要求使用Python编写一个函数,完成百分制成绩到等级制成绩的转换。(60以下为“不及格”,60-69为“及格” ,70-79为“中”,80-89为“良好”,90分以上为’优秀’)。
def score_level(score):
if score < 60:
return "不及格"
elif score < 70:
return "及格"
elif score < 80:
return "中"
elif score < 90:
return "良好"
else:
return "优秀"
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](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)
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)