从键盘输入10个成绩,然后求出最高成绩、最低成绩和它们在数组中的位置。
时间: 2023-04-21 15:06:35 浏览: 62
首先,我们需要定义一个长度为10的数组来存储这10个成绩。然后,我们可以使用循环语句来从键盘输入这10个成绩,并将它们存储到数组中。
接下来,我们可以使用循环语句遍历数组,找到最高成绩和最低成绩,并记录它们在数组中的位置。最后,我们可以输出最高成绩、最低成绩和它们在数组中的位置。
以下是示例代码:
```python
scores = [] * 10 # 定义一个长度为10的数组
# 从键盘输入10个成绩,并将它们存储到数组中
for i in range(10):
scores[i] = int(input("请输入第%d个成绩:" % (i+1)))
# 初始化最高成绩和最低成绩为数组中的第一个元素
max_score = scores[]
min_score = scores[]
max_index =
min_index =
# 遍历数组,找到最高成绩和最低成绩,并记录它们在数组中的位置
for i in range(1, 10):
if scores[i] > max_score:
max_score = scores[i]
max_index = i
elif scores[i] < min_score:
min_score = scores[i]
min_index = i
# 输出最高成绩、最低成绩和它们在数组中的位置
print("最高成绩为:%d,位置为:%d" % (max_score, max_index))
print("最低成绩为:%d,位置为:%d" % (min_score, min_index))
```
运行程序后,可以依次输入10个成绩,然后程序会输出最高成绩、最低成绩和它们在数组中的位置。