编程评定学生成绩,成绩≥90 为优秀;90>成绩≥80 为良好;80>成绩≥70 为中等70>成绩≥60 为及格;60>成绩为不及格。(分别用if 语句和 switch 语句编写程序)。
时间: 2023-05-14 16:06:37 浏览: 65
好的,以下是用 if 语句和 switch 语句分别编写的程序:
if 语句:
```
score = 85
if score >= 90:
print("优秀")
elif score >= 80:
print("良好")
elif score >= 70:
print("中等")
elif score >= 60:
print("及格")
else:
print("不及格")
```
switch 语句:
```
score = 85
def switch_case(score):
switcher = {
90 <= score <= 100: "优秀",
80 <= score < 90: "良好",
70 <= score < 80: "中等",
60 <= score < 70: "及格",
score < 60: "不及格"
}
return switcher.get(True, "无效的成绩")
print(switch_case(score))
```
希望这些代码能够帮助你!
相关问题
编程评定学生成绩,成绩三90为优秀:90>成绩≥80 为良好;80>成绩≥70 为中等; 70-成绩二60为及格;60-成绩为不及格。(分别用计语句和 switch 语句编写程序》
以下是使用 C 语言编写的计语句和 switch 语句实现编程评定学生成绩的程序:
使用计语句:
#include <stdio.h>
int main() { float score; printf("请输入学生成绩:"); scanf("%f", &score);
if (score >= 90) { printf("优秀\n"); } else if (score >= 80) { printf("良好\n"); } else if (score >= 70) { printf("中等\n"); } else if (score >= 60) { printf("及格\n"); } else { printf("不及格\n"); }
return 0; }
使用 switch 语句:
#include <stdio.h>
int main() { float score; printf("请输入学生成绩:"); scanf("%f", &score);
switch ((int)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; }
输入成绩,评定等级,>=90为优秀,>=75为良好,>=60为及格,否则不及格,c语言
这道题目要求根据输入的成绩评定等级,其中>=90为优秀,>=75为良好,>=60为及格,否则不及格。下面是一个C语言的实现代码:
```
#include <stdio.h>
int main() {
int score;
char grade;
scanf("%d", &score);
if (score >= 90) {
grade = 'A';
} else if (score >= 75) {
grade = 'B';
} else if (score >= 60) {
grade = 'C';
} else {
grade = 'D';
}
printf("成绩等级:%c\n", grade);
return 0;
}
```
这个代码中,我们首先定义了一个整型变量score和一个字符型变量grade,用于存储输入的成绩和评定的等级。然后使用scanf函数从标准输入中读取一个整数,即输入的成绩。接着使用if-else语句判断成绩所属的等级,并将对应的等级字符赋值给grade变量。最后使用printf函数输出评定的等级。
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![asm](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)