输入一个学生的成绩(0-100),对学生成绩进行评定用ifelse
时间: 2024-03-19 08:46:22 浏览: 43
好的,以下是使用 if-else 语句对学生成绩进行评定的示例代码:
```
score = int(input("请输入学生的成绩(0-100):"))
if score >= 90:
print("优秀")
elif score >= 80:
print("良好")
elif score >= 70:
print("中等")
elif score >= 60:
print("及格")
else:
print("不及格")
```
以上代码中,首先读取用户输入的成绩,并将其转换为整数类型。然后使用 if-else 语句对成绩进行判断,根据不同的分数区间输出不同的评定结果。
相关问题
输入一个学生的成绩(0-100),对学生成绩进行评定用ifelse,yongC语言制作
好的,以下是使用 if-else 语句对学生成绩进行评定的示例代码,使用 C 语言实现:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入学生的成绩(0-100):");
scanf("%d", &score);
if (score >= 90) {
printf("优秀");
} else if (score >= 80) {
printf("良好");
} else if (score >= 70) {
printf("中等");
} else if (score >= 60) {
printf("及格");
} else {
printf("不及格");
}
return 0;
}
```
以上代码中,首先使用 `printf` 函数输出提示信息,让用户输入成绩,并使用 `scanf` 函数读取用户输入的数值。然后使用 if-else 语句对成绩进行判断,根据不同的分数区间输出不同的评定结果,使用 `printf` 函数输出评定结果。最后使用 `return` 语句结束程序。
输入一个学生的成绩(0-100),对学生成绩进行评定用ifelse,用C语言制作结果<0或者>100
好的,以下是使用 if-else 语句对学生成绩进行评定的示例代码,使用 C 语言实现。同时,代码中还添加了对输入成绩小于 0 或大于 100 的情况进行处理:
```c
#include <stdio.h>
int main() {
int score;
printf("请输入学生的成绩(0-100):");
scanf("%d", &score);
if (score < 0 || score > 100) {
printf("输入的成绩无效");
} else if (score >= 90) {
printf("优秀");
} else if (score >= 80) {
printf("良好");
} else if (score >= 70) {
printf("中等");
} else if (score >= 60) {
printf("及格");
} else {
printf("不及格");
}
return 0;
}
```
以上代码中,首先使用 `printf` 函数输出提示信息,让用户输入成绩,并使用 `scanf` 函数读取用户输入的数值。然后使用 if-else 语句对成绩进行判断,首先判断输入的成绩是否小于 0 或大于 100,如果是,则输出“输入的成绩无效”,否则根据不同的分数区间输出不同的评定结果,使用 `printf` 函数输出评定结果。最后使用 `return` 语句结束程序。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)