头歌python百分制成绩转
时间: 2024-09-27 18:14:54 浏览: 35
python 百分制成绩转等级制成绩 示例
5星 · 资源好评率100%
在Python中,如果你想将百分制的成绩转换成等级,比如常见的90分以上为A,80-89为B+,70-79为B,以此类推,你可以编写一个简单的函数来实现这个功能。以下是一个示例:
```python
def convert_grade(score):
if score >= 90:
grade = 'A'
elif 80 <= score < 90:
grade = 'B+'
elif 70 <= score < 80:
grade = 'B'
elif 60 <= score < 70:
grade = 'C'
elif 60 > score >= 50:
grade = 'D'
else:
grade = 'F'
return grade
# 示例
score = 85
converted_grade = convert_grade(score)
print(f"Score {score} is equivalent to a {converted_grade}.")
阅读全文