编写成绩等级转换程序,提示用户输入成绩(score),根据如下分段规则输出成绩等级:A:score>90,B:90>score>=80,C:80>score>=70,D:70>score>=60,E:score<60
时间: 2024-02-20 07:56:46 浏览: 32
好的,以下是 Python 代码实现:
```python
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")
```
使用 `input()` 函数获取用户输入成绩,使用 `float()` 函数将输入的字符串类型转换为浮点数类型。根据分段规则使用 `if...elif...else` 语句进行判断,输出对应的成绩等级。
相关问题
编写程序,输入学生成绩score后,输出对应的等级。对应关系如下:score≥90:
输出A;80≤score<90:输出B;70≤score<80:输出C;60≤score<70:输出D;score<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")
```
这个程序可以根据输入的学生成绩,输出对应的等级。
输入学生的成绩(整型),根据成绩输出该学生的成绩等级:
好的,以下是一个简单的 Python 代码示例,可以实现输入学生成绩并输出成绩等级的功能:
```python
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")
```
该程序会提示用户输入学生的成绩,然后根据成绩的不同范围输出相应的等级,其中 A、B、C、D、E 分别代表优、良、中、及格、不及格。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)