1.成绩转化 【问题描述】输入小明百分制成绩,输出相应的等级:90分以上为'A’,80分到89分为'B’,7吩到7分为'c’,60分到69分为'D’,60分以下为'E’,如果分数大于100或者小于0,则输出“成绩有误”。 【输入形式】百分制整数成绩 【输出形式】等级字母或错误提示【样例输入】93【样例输出】A
时间: 2023-06-03 11:02:03 浏览: 99
这是一道简单的编程题,可以使用条件语句来处理。以下是Python的代码实现:
score = int(input())
if score < 0 or score > 100:
print("成绩有误")
elif score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 70:
print("C")
elif score >= 60:
print("D")
else:
print("E")
相关问题
输入小明百分制成绩,输出相应的等级:90分以上为‘A’,80分到89分为‘B’,70分到7分为‘C’,60分到69分为‘D’,60分以下为‘E’,如果分数大于100或者小于0,则输出“成绩有误”。(10分)
好的,这是一个简单的if-else条件语句,可以用Python来实现,代码如下:
```
score = float(input("请输入小明的百分制成绩:"))
if score > 100 or score < 0:
print("成绩有误")
elif score >= 90:
print("等级为:A")
elif score >= 80:
print("等级为:B")
elif score >= 70:
print("等级为:C")
elif score >= 60:
print("等级为:D")
else:
print("等级为:E")
```
这段代码中,我们首先使用`input()`函数获取用户输入的成绩,然后使用`float()`函数将输入的字符串转换为浮点数类型。
然后,我们使用if-else条件语句进行判断,如果成绩大于100或小于0,就输出“成绩有误”,否则根据不同的分数段,输出对应的等级。注意,if-elif-else语句的顺序不能颠倒,否则会出现逻辑错误。
希望这个答案能够帮助到你!
编写python程序输入小明百分制成绩,输出相应的等级:90分以上为‘A’,80分到89分为‘B’,70分到7分为‘C’,60分到69分为‘D’,60分以下为‘E’,如果分数大于100或者小于0,则输出“成绩有误”。
好的,以下是Python代码实现该功能:
```python
score = float(input("请输入小明的成绩:"))
if score >= 90 and score <= 100:
print("小明的成绩等级为:A")
elif score >= 80 and score < 90:
print("小明的成绩等级为:B")
elif score >= 70 and score < 80:
print("小明的成绩等级为:C")
elif score >= 60 and score < 70:
print("小明的成绩等级为:D")
elif score >= 0 and score < 60:
print("小明的成绩等级为:E")
else:
print("成绩有误")
```
其中,我们使用了 `if-elif-else` 语句来判断小明的成绩所对应的等级。需要注意的是,我们用 `float()` 将输入的字符串转换成浮点数,以便进行比较。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.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)