从键盘输入五名同学的百分制成绩,统计各个分数段的人数,然后根据输入指定分数段查询该分数段的人数,分数段的定义为:第一段成绩大于等于90:第二段成绩大于等于八十且小于九十;第三段成绩大于等于七十且小于八十;第四段成绩大于等于六十且小于七十;第五段成绩小于六十
时间: 2023-08-24 11:10:56 浏览: 57
好的,这个问题可以使用 Python 编程语言来解决。下面是实现代码:
```python
# 统计分数段人数
def count_score(scores):
count = [0] * 5
for score in scores:
if score >= 90:
count[0] += 1
elif score >= 80:
count[1] += 1
elif score >= 70:
count[2] += 1
elif score >= 60:
count[3] += 1
else:
count[4] += 1
return count
# 查询指定分数段人数
def query_score(scores, low, high):
count = 0
for score in scores:
if score >= low and score < high:
count += 1
return count
# 主函数
if __name__ == "__main__":
scores = []
for i in range(5):
score = int(input("请输入第%d名同学的成绩:" % (i+1)))
scores.append(score)
count = count_score(scores)
print("90分及以上:", count[0], "人")
print("80分及以上:", count[1], "人")
print("70分及以上:", count[2], "人")
print("60分及以上:", count[3], "人")
print("60分以下:", count[4], "人")
low = int(input("请输入查询的分数段下限:"))
high = int(input("请输入查询的分数段上限:"))
query_count = query_score(scores, low, high)
print("在%d分至%d分之间的人数为%d人" % (low, high, query_count))
```
运行代码后,输入五个同学的成绩和查询分数段的下限和上限,即可得到各个分数段的人数和指定分数段的人数。