输入学生的百分制成绩s,根据其值,输出其等级成绩。90分以上为优秀,80分以上为良好,70分以上为中等,60分以为及格,不足60分为不及格。
时间: 2024-03-03 10:48:02 浏览: 18
好的,这是一个简单的分支结构问题,可以使用 if-else 语句实现。以下是示例代码:
```
score = float(input("请输入学生的成绩:"))
if score >= 90:
print("优秀")
elif score >= 80:
print("良好")
elif score >= 70:
print("中等")
elif score >= 60:
print("及格")
else:
print("不及格")
```
使用 `input` 函数获取用户输入的成绩,然后使用 if-else 语句判断成绩的等级,最后使用 print 函数输出结果。
相关问题
用C语言给出一百分制成绩,要求输出成绩等级A,90分以上的为A
可以使用以下代码实现:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入成绩:");
scanf("%d", &score);
if (score >= 90) {
printf("成绩等级为A\n");
} else {
printf("成绩等级为B及以下\n");
}
return 0;
}
```
注意:这里只是一个简单的示例代码,实际应用中需要考虑更多的情况,比如输入的成绩是否合法等。
输入一个百分制成绩t后 按下式输出它的等级 要求写成swith结构 等级划分为
90-100为A级,80-89为B级,70-79为C级,60-69为D级,60以下为E级。
代码如下:
```python
t = float(input("请输入百分制成绩:"))
# 判断成绩等级
if t < 0 or t > 100:
print("输入错误,请重新输入!")
else:
score = int(t // 10)
grade = ""
# 利用switch结构输出成绩等级
switch = {
10: "A",
9: "A",
8: "B",
7: "C",
6: "D",
5: "E",
4: "E",
3: "E",
2: "E",
1: "E",
0: "E"
}
grade = switch.get(score, "输入错误,请重新输入!")
print("该成绩的等级为:", grade)
```
运行结果:
```
请输入百分制成绩:85
该成绩的等级为: B
```
相关推荐
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)