fork download
  1. # 定义学生成绩列表
  2. student_score = [78, 65, 92, 78, 90, 45, 83, 57, 96, 56]
  3. # 定义总成绩变量
  4. sum_score = 0
  5. # 遍历 求总成绩
  6. for score in student_score:
  7. # 累加成绩
  8. sum_score += score
  9. # 定义平均成绩变量
  10. avreage_score = sum_score/len(student_score)
  11. # 打印总成绩和平均成绩
  12. print(f'总成绩为:{sum_score}, 平均成绩为:{avreage_score}')
  13.  
  14. # 定义大于等于平均成绩的个数的变量
  15. avreage_count = 0
  16. # 求个数 遍历
  17. for score in student_score:
  18. # 验证
  19. if score >= avreage_score:
  20. avreage_count += 1
  21.  
  22. # 打印大于等于平均成绩的个数
  23. print(f'大于等于平均成绩的个数为:{avreage_count}')
Success #stdin #stdout 0.08s 14156KB
stdin
Standard input is empty
stdout
总成绩为:740, 平均成绩为:74.0
大于等于平均成绩的个数为:6