Advertisement
DevNeon

Untitled

Oct 21st, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.10 KB | None | 0 0
  1. # Exam-20191022.py
  2. import random
  3. import math
  4. import sys
  5.  
  6. class Score :
  7.    
  8.     # 생성자
  9.     def __init__(self) :
  10.         self.std_sheet = [None] * 3
  11.         self.subScore = [0] * 3
  12.         self.tot = 0
  13.         self.ave = 0
  14.         self.grade = ""
  15.        
  16.         # 0부터 (2^n)-1 사의의 수는 2진수로 변환했을때 n칸만큼의 2진수이므로 이를 이용해 0과 1로 이루어진 답안 배열을 생성
  17.         for sub in range(0, 3) :
  18.             self.std_sheet[sub] = [0] * 20
  19.             temp = str( bin( random.randrange( 0, math.pow( 2, 20 ) ) )[2:] )
  20.             count = 0
  21.             for i in range(len(self.std_sheet[sub]) - len(temp), 20) :
  22.                 self.std_sheet[sub][i] = int(temp[count])
  23.                 count += 1
  24.  
  25.     # 답지 조정 메소드 (무조건 8개 이상 맞게)
  26.     def Edit(self, sub, A_sheet) :
  27.         for i in range (0, random.randrange( 8, len(A_sheet) ) ) :
  28.             A_sheet[i] = self.std_sheet[sub][i]
  29.        
  30.     # 점수 연산 및 OX 출력 메소드
  31.     def Cal(self, sub, A_sheet) :
  32.         for i in range (0, len(A_sheet) ) :
  33.             if (A_sheet[i] == self.std_sheet[sub][i]) :
  34.                 print("O", end=" ")
  35.                 self.subScore[sub] += 1
  36.             else :
  37.                 print("X", end=" ")
  38.         self.subScore[sub] = self.subScore[sub] * 5
  39.         self.tot += self.subScore[sub]
  40.         print("%d"%(self.subScore[sub]))
  41.  
  42.     # 표 출력 메소드
  43.     def Info(self) :
  44.         self.ave = self.tot / 3
  45.         if self.ave >= 95 :
  46.             self.grade = "A+"
  47.         elif self.ave >= 90 :
  48.             self.grade = "A0"
  49.         elif self.ave >= 85 :
  50.             self.grade = "B+"
  51.         elif self.ave >= 80 :
  52.             self.grade = "B0"
  53.         elif self.ave >= 75 :
  54.             self.grade = "C+"
  55.         elif self.ave >= 70 :
  56.             self.grade = "C0"
  57.         else :
  58.             self.grade = "F"
  59.         print("    %3d     %3d     %3d     %3d     %3d      %s" % (self.subScore[0], self.subScore[1], self.subScore[2], self.tot, self.ave, self.grade))
  60.  
  61.     def subInfo(self, sub) :
  62.         print(1)
  63.  
  64. # 사용할 변수 초기화
  65. subAve = [0] * 3 # 과목 평균
  66. subDis = [0] * 3 # 과목 분산
  67. subDev = [None] * 3 # 편차 / 편차 제곱
  68.  
  69. # 입력받기
  70. num = int(input("학생수를 입력해주세요 : "))
  71. score = [None] * num
  72. A_sheet = [None] * 3
  73. for sub in range(0, 3) :
  74.     subDev[sub] = [0] * num
  75.  
  76. # 답안 초기화
  77. # 0부터 (2^n)-1 사의의 수는 2진수로 변환했을때 n칸만큼의 2진수이므로 이를 이용해 0과 1로 이루어진 정답안 배열을 생성
  78. for sub in range(0, 3) :
  79.     A_sheet[sub] = [0] * 20
  80.     temp = str( bin( random.randrange( 0, math.pow( 2, 20 ) ) )[2:] )
  81.     count = 0
  82.     for i in range(len(A_sheet[sub]) - len(temp), 20) :
  83.         A_sheet[sub][i] = int(temp[count])
  84.         count += 1
  85.  
  86. # 객체 불러오기
  87. for i in range(0, num) :
  88.     score[i] = Score()
  89.  
  90. # 학생 답 연산 및 OX 출력 (Random으로 답이 작성되어 평균치가 낮음으로 임의 점수 수정도 같이 진행)
  91. for sub in range(0, 3) :
  92.     if sub == 0 :
  93.         print("[언어 영역]")
  94.     elif sub == 1 :
  95.         print("[외국어 영역]")
  96.     elif sub == 2 :
  97.         print("[수리 영역]")
  98.     for i in range(0, num) :
  99.         print(" └%3d번" % (i+1), end=" ")
  100.         score[i].Edit(sub, A_sheet[sub])
  101.         score[i].Cal(sub, A_sheet[sub])
  102.         subAve[sub] += score[i].subScore[sub]
  103.     print("")
  104.  
  105. # 표 출력
  106. print("──────────────────────────────")
  107. print("         언어  외국어    수리    총점    평균    학점")
  108. for i in range(0, num) :
  109.     print("%3d번" % (i+1), end="")
  110.     score[i].Info()
  111. print("──────────────────────────────")
  112.  
  113. # 상세 표 연산 및 출력부
  114. Max = [0] * 3
  115. Min = [100] * 3
  116. for sub in range(0, 3) :
  117.     subAve[sub] = subAve[sub] / num
  118.  
  119. # 최대 최소값 구하기
  120. for i in range(0, num) :
  121.     for sub in range(0, 3) :
  122.         if Max[sub] < score[i].subScore[sub] :
  123.             Max[sub] = score[i].subScore[sub]
  124.         if Min[sub] > score[i].subScore[sub] :
  125.             Min[sub] = score[i].subScore[sub]
  126.  
  127. # 편차 / 편차제곱 구하기
  128. for sub in range(0, 3) :
  129.     for i in range(0, num) :
  130.         subDev[sub][i] = score[i].subScore[sub] - subAve[sub]
  131.         subDev[sub][i] = math.pow(subDev[sub][i], 2)
  132.         subDis[sub] += subDev[sub][i]
  133.  
  134. # 분산 구하기
  135. for sub in range(0, 3) :
  136.     subDis[sub] = subDis[sub] / num
  137.  
  138. # 상세 표 연산 및 출력
  139. print("  MAX    %3d     %3d     %3d" % (Max[0], Max[1], Max[2]))
  140. print("  MIN    %3d     %3d     %3d" % (Min[0], Min[1], Min[2]))
  141. print("  평균   %3d     %3d     %3d" % (subAve[0], subAve[1], subAve[2]))
  142. print("  분산   %3.0f     %3.0f     %3.0f" % (subDis[0], subDis[1], subDis[2]))
  143. print("표준편차 %3.0f     %3.0f     %3.0f" % (math.sqrt(subDis[0]), math.sqrt(subDis[1]), math.sqrt(subDis[2]) ) )
  144. print("──────────────────────────────")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement