python编程从键盘输入7个学生的考试成绩(百分制),统计并输出他们的平均成绩(保留2位小数),并将考试成绩排降序输出。 输入输出格式如下: 67 86 78 99 58 78 97 7个学生的平均分为: 80.43 成绩排降序为: [99, 97, 86, 78, 78, 67, 58]
时间: 2024-03-18 14:38:55 浏览: 145
好的,这是一个很简单的Python编程题目,下面是代码实现:
```python
# 从键盘输入7个学生的成绩
scores = input("请输入7个学生的考试成绩,用空格隔开:")
scores_list = scores.split()
scores_list = [int(score) for score in scores_list]
# 计算平均成绩
avg_score = round(sum(scores_list) / len(scores_list), 2)
print("7个学生的平均分为:", avg_score)
# 将考试成绩排降序输出
scores_list.sort(reverse=True)
print("成绩排降序为:", scores_list)
```
代码实现很简单,首先从键盘输入7个学生的成绩,将输入的字符串使用split()方法分割成一个列表,然后使用列表推导式将列表中的每个字符串转换成整数类型,得到一个整数列表。接着计算平均成绩,使用round()函数保留两位小数。最后将成绩列表使用sort()方法进行降序排序,输出即可。
相关问题
编写python程序,从键盘输入语文数学英语三门课程成绩,计算输出平均成绩,并保留一位小数
可以使用以下代码实现:
```python
chinese_score = float(input("请输入语文成绩:"))
math_score = float(input("请输入数学成绩:"))
english_score = float(input("请输入英语成绩:"))
average_score = (chinese_score + math_score + english_score) / 3
print("三门课程的平均成绩为:{:.1f}".format(average_score))
```
在这个程序中,我们首先使用`input`函数从键盘输入三门课程的成绩,并将其转换为浮点数类型。然后,我们计算三门课程的平均成绩,并使用`format`函数将其格式化为保留一位小数的字符串。最后,我们使用`print`函数输出平均成绩。
1、从键盘上输入10个学生的成绩, 统计并输出最高成绩、最低成绩和平均成绩(保留小数点后2位)。
为了统计并输出10个学生的成绩,你可以编写一个简单的程序,通常使用控制台输入或用户界面。这里是一个用Python编写的示例:
```python
# 初始化变量
scores = []
max_score = float('-inf')
min_score = float('inf')
total = 0
# 输入10个学生的成绩
for i in range(10):
score = float(input(f"请输入第{i+1}名学生的成绩:"))
scores.append(score)
# 更新最高分和最低分
max_score = max(max_score, score)
min_score = min(min_score, score)
# 计算平均成绩
if scores:
average = sum(scores) / len(scores)
else:
average = 0
# 输出结果,保留小数点后两位
average = round(average, 2)
print(f"最高成绩:{max_score:.2f}")
print(f"最低成绩:{min_score:.2f}")
print(f"平均成绩:{average:.2f}")
阅读全文
相关推荐














