写一个程序 在键盘上输入10个学生的成绩 统计最高分 最低分 和平均分
时间: 2024-02-20 16:56:26 浏览: 40
好的,这是一个基于 Python 语言的程序,可以实现你的需求:
```python
scores = []
for i in range(10):
score = int(input("请输入第%d个学生的成绩:" % (i+1)))
scores.append(score)
max_score = max(scores)
min_score = min(scores)
avg_score = sum(scores) / len(scores)
print("最高分为:", max_score)
print("最低分为:", min_score)
print("平均分为:", avg_score)
```
程序的实现很简单,首先定义一个空列表 scores,然后使用 for 循环输入 10 个学生的成绩,将成绩添加到 scores 列表中。接着使用内置函数 max、min 和 sum 计算最高分、最低分和平均分,最后输出结果即可。
相关问题
编写一个程序,在键盘上输入 10 个学生的成绩,统计最高分、最低分和平均分。
好的,以下是 Python 代码实现:
```python
scores = []
for i in range(10):
score = float(input("请输入第{}个学生的成绩: ".format(i+1)))
scores.append(score)
max_score = max(scores)
min_score = min(scores)
avg_score = sum(scores) / len(scores)
print("最高分为:{}".format(max_score))
print("最低分为:{}".format(min_score))
print("平均分为:{}".format(avg_score))
```
这个程序会提示你输入 10 个学生的成绩,然后计算出最高分、最低分和平均分,并输出结果。
30、编写一个程序,从键盘输入10个学生成绩存入一维数组中,统计最高分、最低分和平均分。
下面是一个 C++ 程序的例子,实现了输入学生成绩并统计最高分、最低分和平均分的功能:
```c++
#include <iostream>
using namespace std;
int main() {
const int num = 10; // 学生数量
int scores[num]; // 存放学生成绩的数组
int max_score, min_score, sum = 0;
double avg_score;
// 输入学生成绩
cout << "请输入 " << num << " 个学生的成绩:" << endl;
for (int i = 0; i < num; i++) {
cin >> scores[i];
sum += scores[i];
if (i == 0) {
max_score = min_score = scores[i];
} else {
if (scores[i] > max_score) max_score = scores[i];
if (scores[i] < min_score) min_score = scores[i];
}
}
// 计算平均分并输出结果
avg_score = (double)sum / num;
cout << "最高分:" << max_score << endl;
cout << "最低分:" << min_score << endl;
cout << "平均分:" << avg_score << endl;
return 0;
}
```
程序中使用了一个 `for` 循环遍历数组输入学生成绩,并在输入时就同时计算最高分、最低分和总分。在循环结束后计算平均分并输出结果。注意要将 `sum` 转换为 `double` 类型再计算平均分。