Python输入百分之成绩,输出对应的5分制等级(90分以上为A;80-90为B,以此类推,60分以下为E)
时间: 2024-05-19 09:12:35 浏览: 12
score = float(input("请输入百分之成绩:"))
if score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 70:
print("C")
elif score >= 60:
print("D")
else:
print("E")
相关问题
编写一个python函数,输入一个分数,判断对应的等级。(90分以上为A,80-90 分以上为 B 60-80分以下是C,60以下为D )
可以使用函数来实现分数等级的判断,代码如下:
```python
def get_grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 60:
return "C"
else:
return "D"
```
以上代码定义了一个名为 `get_grade` 的函数,参数为 `score`,即学生的分数。函数内部使用 `if-elif-else` 语句对分数进行判断,并返回对应的等级。可以通过调用该函数来获取学生的等级,例如:
```python
score = float(input("请输入学生成绩:"))
grade = get_grade(score)
print("学生的等级为:", grade)
```
以上代码先从用户输入中获取学生的分数,然后调用 `get_grade` 函数获取对应的等级,最后输出学生的等级。
在python中,输入成绩,输出对应等级,90以上为a,80~90为b,70~80为c,60~70为d,60以下为e。
以下是代码实现:
```
score = int(input("请输入成绩:"))
if score >= 90:
print("等级为:A")
elif score >= 80:
print("等级为:B")
elif score >= 70:
print("等级为:C")
elif score >= 60:
print("等级为:D")
else:
print("等级为:E")
```
希望能够帮助到你!
相关推荐
![](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)