编写程序,输入学生成绩score后,输出对应的等级。对应关系如下:score≥90:
时间: 2023-05-11 20:07:02 浏览: 139
输出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")
```
这个程序可以根据输入的学生成绩,输出对应的等级。
相关问题
编写程序完成如下操作,输入同学的成绩score(题目保证成绩是[0,120]区间的一个整数),输出对应等级,对应关系为: score≥90 '优' 80≤score<90 '良' 70≤score<80 '中' 60≤score<70 '合格’ score<60 '不及格' 输入样例: 75 输出样例: 中
好的,以下是Python程序代码:
```python
# 获取用户输入的成绩
score = int(input("请输入成绩:"))
# 判断对应等级
if score >= 90:
level = '优'
elif score >= 80:
level = '良'
elif score >= 70:
level = '中'
elif score >= 60:
level = '合格'
else:
level = '不及格'
# 输出等级
print(level)
```
你可以将代码复制到Python环境中运行,然后输入同学的成绩,即可输出对应的等级。
用switch语句编写输入学生成绩输出等级c语言
下面是使用switch语句编写输入学生成绩输出等级的C语言代码:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入学生成绩:");
scanf("%d", &score);
switch(score / 10) {
case 10:
case 9:
printf("成绩等级为:优秀\n");
break;
case 8:
printf("成绩等级为:良好\n");
break;
case 7:
printf("成绩等级为:中等\n");
break;
case 6:
printf("成绩等级为:及格\n");
break;
default:
printf("成绩等级为:不及格\n");
break;
}
return 0;
}
```
以上代码中,我们首先定义了一个整型变量score来存储输入的学生成绩。然后使用printf函数输出提示信息,使用scanf函数获取用户输入的学生成绩。基于用户输入的成绩,我们使用score / 10来作为switch语句的判断条件,进而输出对应的等级。
其中,case 10和case 9表示成绩在90-100之间,输出"优秀";case 8表示成绩在80-89之间,输出"良好";case 7表示成绩在70-79之间,输出"中等";case 6表示成绩在60-69之间,输出"及格";default表示成绩低于60,输出"不及格"。
最后,我们使用return 0来结束程序的执行。
以上就是用switch语句编写输入学生成绩输出等级的C语言代码。
相关推荐
![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)
![](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)