-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.py
79 lines (69 loc) · 2.08 KB
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import openpyxl
import math
#
# raw_data = {}
# wb = openpyxl.load_workbook('class_2_3.xlsx')
# ws = wb.active
# g = ws.rows
#
# for name, score in g:
# raw_data[name.value] = score.value
# 이 부분을 함수로 리팩토링
def get_data_from_excel(filename):
"""
get_data_from_excel -> {'name1': 'score1','name2': 'score2', ...}
엑셀 파일에서 데이터를 가져옵니다
반환값은 key가 학생 이름이고 value가 점수인 딕셔너리입니다
"""
dic = {}
wb = openpyxl.load_workbook(filename)
ws = wb.active
g = ws.rows
for name, score in g:
dic[name.value] = score.value
return dic
# s = 0
#
# for score in scores:
# s += score
#
# avrg = round(s/len(scores), 1)
#
# s = 0
#
# for score in scores:
# s += (score - avrg) ** 2
#
# variance = round(s/len(scores), 1)
#
# std_dev = round(math.sqrt(variance),1)
#
# 평균, 분산, 표준편차를 구하는 부분 함수로 다시 구현
def average(scores):
s = 0
for score in scores:
s += score
return round(s/len(scores), 1)
def variance(scores, avrg):
s = 0
for score in scores:
s += (score - avrg) ** 2
return round(s/len(scores), 1)
def std_dev(variance):
return round(math.sqrt(variance), 1)
def evaluateClass(avrg, total_avrg, std_dev, sd):
"""
evaluateClass(avrg, total_avrg, std_dev, sd) -> None
avrg: 반 성적 평균
total_avrg: 학년 전체 성적 평균
std_dev: 반의 표준편차
sd: 원하는 표준편차 기준
"""
if avrg < total_avrg and std_dev > sd:
print("성적이 너무 저조하고 학생들의 실력 차이가 너무 크다.")
elif avrg > total_avrg and std_dev > sd:
print("성적은 평균 이상이지만 학생들의 실력 차이가 크다. 주의 요망!")
elif avrg < total_avrg and std_dev < sd:
print("학생들의 실력 차이는 크지 않지만 성적이 너무 저조하다. 주의 요망!")
elif avrg > total_avrg and std_dev < sd:
print("성적도 평균 이상이고 학생들의 실력 차이도 크지 않다.")