Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Exam-20191022.py
- import random
- import math
- import sys
- class Score :
- # 생성자
- def __init__(self) :
- self.std_sheet = [None] * 3
- self.subScore = [0] * 3
- self.tot = 0
- self.ave = 0
- self.grade = ""
- # 0부터 (2^n)-1 사의의 수는 2진수로 변환했을때 n칸만큼의 2진수이므로 이를 이용해 0과 1로 이루어진 답안 배열을 생성
- for sub in range(0, 3) :
- self.std_sheet[sub] = [0] * 20
- temp = str( bin( random.randrange( 0, math.pow( 2, 20 ) ) )[2:] )
- count = 0
- for i in range(len(self.std_sheet[sub]) - len(temp), 20) :
- self.std_sheet[sub][i] = int(temp[count])
- count += 1
- # 답지 조정 메소드 (무조건 8개 이상 맞게)
- def Edit(self, sub, A_sheet) :
- for i in range (0, random.randrange( 8, len(A_sheet) ) ) :
- A_sheet[i] = self.std_sheet[sub][i]
- # 점수 연산 및 OX 출력 메소드
- def Cal(self, sub, A_sheet) :
- for i in range (0, len(A_sheet) ) :
- if (A_sheet[i] == self.std_sheet[sub][i]) :
- print("O", end=" ")
- self.subScore[sub] += 1
- else :
- print("X", end=" ")
- self.subScore[sub] = self.subScore[sub] * 5
- self.tot += self.subScore[sub]
- print("%d"%(self.subScore[sub]))
- # 표 출력 메소드
- def Info(self) :
- self.ave = self.tot / 3
- if self.ave >= 95 :
- self.grade = "A+"
- elif self.ave >= 90 :
- self.grade = "A0"
- elif self.ave >= 85 :
- self.grade = "B+"
- elif self.ave >= 80 :
- self.grade = "B0"
- elif self.ave >= 75 :
- self.grade = "C+"
- elif self.ave >= 70 :
- self.grade = "C0"
- else :
- self.grade = "F"
- print(" %3d %3d %3d %3d %3d %s" % (self.subScore[0], self.subScore[1], self.subScore[2], self.tot, self.ave, self.grade))
- def subInfo(self, sub) :
- print(1)
- # 사용할 변수 초기화
- subAve = [0] * 3 # 과목 평균
- subDis = [0] * 3 # 과목 분산
- subDev = [None] * 3 # 편차 / 편차 제곱
- # 입력받기
- num = int(input("학생수를 입력해주세요 : "))
- score = [None] * num
- A_sheet = [None] * 3
- for sub in range(0, 3) :
- subDev[sub] = [0] * num
- # 답안 초기화
- # 0부터 (2^n)-1 사의의 수는 2진수로 변환했을때 n칸만큼의 2진수이므로 이를 이용해 0과 1로 이루어진 정답안 배열을 생성
- for sub in range(0, 3) :
- A_sheet[sub] = [0] * 20
- temp = str( bin( random.randrange( 0, math.pow( 2, 20 ) ) )[2:] )
- count = 0
- for i in range(len(A_sheet[sub]) - len(temp), 20) :
- A_sheet[sub][i] = int(temp[count])
- count += 1
- # 객체 불러오기
- for i in range(0, num) :
- score[i] = Score()
- # 학생 답 연산 및 OX 출력 (Random으로 답이 작성되어 평균치가 낮음으로 임의 점수 수정도 같이 진행)
- for sub in range(0, 3) :
- if sub == 0 :
- print("[언어 영역]")
- elif sub == 1 :
- print("[외국어 영역]")
- elif sub == 2 :
- print("[수리 영역]")
- for i in range(0, num) :
- print(" └%3d번" % (i+1), end=" ")
- score[i].Edit(sub, A_sheet[sub])
- score[i].Cal(sub, A_sheet[sub])
- subAve[sub] += score[i].subScore[sub]
- print("")
- # 표 출력
- print("──────────────────────────────")
- print(" 언어 외국어 수리 총점 평균 학점")
- for i in range(0, num) :
- print("%3d번" % (i+1), end="")
- score[i].Info()
- print("──────────────────────────────")
- # 상세 표 연산 및 출력부
- Max = [0] * 3
- Min = [100] * 3
- for sub in range(0, 3) :
- subAve[sub] = subAve[sub] / num
- # 최대 최소값 구하기
- for i in range(0, num) :
- for sub in range(0, 3) :
- if Max[sub] < score[i].subScore[sub] :
- Max[sub] = score[i].subScore[sub]
- if Min[sub] > score[i].subScore[sub] :
- Min[sub] = score[i].subScore[sub]
- # 편차 / 편차제곱 구하기
- for sub in range(0, 3) :
- for i in range(0, num) :
- subDev[sub][i] = score[i].subScore[sub] - subAve[sub]
- subDev[sub][i] = math.pow(subDev[sub][i], 2)
- subDis[sub] += subDev[sub][i]
- # 분산 구하기
- for sub in range(0, 3) :
- subDis[sub] = subDis[sub] / num
- # 상세 표 연산 및 출력
- print(" MAX %3d %3d %3d" % (Max[0], Max[1], Max[2]))
- print(" MIN %3d %3d %3d" % (Min[0], Min[1], Min[2]))
- print(" 평균 %3d %3d %3d" % (subAve[0], subAve[1], subAve[2]))
- print(" 분산 %3.0f %3.0f %3.0f" % (subDis[0], subDis[1], subDis[2]))
- print("표준편차 %3.0f %3.0f %3.0f" % (math.sqrt(subDis[0]), math.sqrt(subDis[1]), math.sqrt(subDis[2]) ) )
- print("──────────────────────────────")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement