编写一个能统计一组输入的学生成绩数据特征的小程序 python
时间: 2023-10-26 13:02:49 浏览: 193
Python例题(一) 输入一个正整数判断是不是素数
以下是一个简单的能统计学生成绩数据特征的Python程序:
```python
def read_grades():
grades = []
num_students = int(input("请输入学生的数量:"))
for i in range(num_students):
grade = float(input("请输入学生的成绩:"))
grades.append(grade)
return grades
def calculate_average(grades):
total = sum(grades)
average = total / len(grades)
return average
def calculate_highest(grades):
highest = max(grades)
return highest
def calculate_lowest(grades):
lowest = min(grades)
return lowest
def calculate_range(grades):
highest = calculate_highest(grades)
lowest = calculate_lowest(grades)
grade_range = highest - lowest
return grade_range
def calculate_variance(grades):
average = calculate_average(grades)
variance = sum((grade - average) ** 2 for grade in grades) / len(grades)
return variance
def calculate_standard_deviation(grades):
variance = calculate_variance(grades)
standard_deviation = variance ** 0.5
return standard_deviation
def main():
grades = read_grades()
print("平均成绩:", calculate_average(grades))
print("最高成绩:", calculate_highest(grades))
print("最低成绩:", calculate_lowest(grades))
print("成绩范围:", calculate_range(grades))
print("成绩方差:", calculate_variance(grades))
print("成绩标准差:", calculate_standard_deviation(grades))
if __name__ == "__main__":
main()
```
这个程序首先会要求用户输入学生的数量,然后逐个输入每个学生的成绩。接着,程序会计算这组成绩的平均值、最高值、最低值、成绩范围、方差和标准差,并将结果输出。
阅读全文