用python程序设计:从键盘输入学生成绩,根据成绩判断学生的等级: 1.90-100分为优秀; 2.80-89分为良好; 3.70-79分为中等; 4.60-69分为及格; 5.0-59分为不及格; 6.其他分数为:成绩有误。
时间: 2023-12-24 11:04:15 浏览: 94
好的,这是一个简单的Python程序。请参考以下代码:
```python
score = int(input("请输入学生成绩:"))
if score >= 90 and score <= 100:
print("优秀")
elif score >= 80 and score <= 89:
print("良好")
elif score >= 70 and score <= 79:
print("中等")
elif score >= 60 and score <= 69:
print("及格")
elif score >= 0 and score <= 59:
print("不及格")
else:
print("成绩有误")
```
首先,我们通过 `input()` 函数从键盘输入学生成绩,然后将其转换为整数类型并存储在 `score` 变量中。
接下来,我们使用条件语句 `if-elif-else` 来根据学生成绩判断其等级。如果学生成绩在90-100分之间,则输出“优秀”;如果在80-89分之间,则输出“良好”;如果在70-79分之间,则输出“中等”;如果在60-69分之间,则输出“及格”;如果在0-59分之间,则输出“不及格”;如果学生成绩不在上述范围内,则输出“成绩有误”。
希望这个例子对你有帮助!
相关问题
用python程序设计:从键盘输入学生成绩,根据成绩判断学生的等级: 1.90-100分为优秀; 2.80-89分为良好; 3.70-79分为中等; 4.60-69分为及格; 5.0-59分为不及格; 6.其他分数为:成绩有误。
好的,以下是Python程序设计实现:
```python
score = input("请输入学生的成绩:") # 从键盘输入学生成绩
score = int(score) # 将输入的成绩转换为整数类型
if score >= 90 and score <= 100:
print("优秀")
elif score >= 80 and score <= 89:
print("良好")
elif score >= 70 and score <= 79:
print("中等")
elif score >= 60 and score <= 69:
print("及格")
elif score >= 0 and score <= 59:
print("不及格")
else:
print("成绩有误")
```
以上程序先从键盘输入学生成绩,然后根据成绩的范围进行判断,输出对应的等级。注意,这里使用了`if-elif-else`语句来实现判断。
python编写函数level,要求可以根据输入的成绩判断其等级。等级设定:90-100为优秀
给定输入成绩,编写一个函数level判断其等级。根据题目要求,等级设定为90-100为优秀。
以下是一个Python函数level的示例代码:
```python
def level(score):
if score >= 90 and score <= 100:
return "优秀"
else:
return "无等级"
# 示例调用
score = float(input("请输入成绩:"))
grade = level(score)
if grade == "无等级":
print("成绩无法判断等级,请重新输入")
else:
print("您的等级是:" + grade)
```
函数`level`接受一个输入参数`score`,并根据输入来判断成绩等级。如果成绩满足90到100的范围,则返回字符串"优秀",否则返回字符串"无等级"表示无法判断等级。
在示例调用中,先要求用户输入成绩,然后调用函数`level`来判断等级,并根据返回结果输出对应的提示信息。如果返回等级为"无等级",则会提示用户重新输入成绩。
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](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)