수능성적표 만드는 과제인데요
잘안되어서요 요기밑에 우선 제가 써본건데
뭐가문제인지봐줄수있으신분 계신가요 ?
클래스를이용하여 학교이름수헙번호등급백분위 나오게하는것이에요
class student:
def __init__(self, name=None, highSchool=None, number=0, natScore=0, matScore=0, engScore=0):
self.__name=name
self.__highSchool=highSchool
self.__number=number
self.__natScore=natScore
self.__matScore=matScore
self.__engScore=engScore
def setName(self, name):
self.__name=name
def getName(self):
return self.__name
def setHighSchool(self, highSchool):
self.__highSchool=highSchool
def getHighSchool(self):
return self.__highSchool
def setnatScore(self, natScore):
self.__natScore=natScore
def getnatScore(self):
return self.__natScore
def setmatScore(self, matScore):
self.__matScore=matScore
def getmatScore(self):
return self.__matScore
def setengScore(self, engScore):
self.__engScore=engScore
def getengScore(self):
return self.__engScore
def clacNatGrade(self):
if self.__natScore>=90:
self.__natScore= '1등급'
elif self.__natScore>=80:
self.__natScore= '2등급'
elif self.__natScore>=70:
self.__natScore= '3등급'
elif self.__natScore>=60:
self.__natScore= '4등급'
elif self.__natScore>=50:
self.__natScore= '5등급'
elif self.__natScore>=40:
self.__natScore= '6등급'
elif self.__natScore>=30:
self.__natScore= '7등급'
elif self.__natScore>=20:
self.__natScore= '8등급'
else:
self.__natScore= '9등급'
def clacMatGrade(self):
if self.__matScore>=90:
self.__matScore= '1등급'
elif self.__matScore>=80:
self.__matScore= '2등급'
elif self.__matScore>=70:
self.__matScore= '3등급'
elif self.__matScore>=60:
self.__matScore= '4등급'
elif self.__matScore>=50:
self.__matScore= '5등급'
elif self.__matScore>=40:
self.__matScore= '6등급'
elif self.__matScore>=30:
self.__matScore= '7등급'
elif self.__matScore>=20:
self.__matScore= '8등급'
else:
self.__matScore= '9등급'
def clacEngGrade(self):
if self.__engScore>=90:
self.__engScore= '1등급'
elif self.__engScore>=80:
self.__engScore= '2등급'
elif self.__engScore>=70:
self.__engScore= '3등급'
elif self.__engScore>=60:
self.__engScore= '4등급'
elif self.__engScore>=50:
self.__engScore= '5등급'
elif self.__engScore>=40:
self.__engScore= '6등급'
elif self.__engScore>=30:
self.__engScore= '7등급'
elif self.__engScore>=20:
self.__engScore= '8등급'
else:
self.__engScore= '9등급'
등급계산 기능이 전체 요구사항에비해 코드길이가 깁니다
일단 한줄로 처리합니다
— grade 계산 중복 —> 함수하나로 추출 —> (10 - 점수의10의자리) 하면 1..9 등급추출
요구사항 분석을 더 구체화해서 요구한것만 최소로 러프하게 만듭니다 이쁘게 만들려면 끝이 없습니다 (getter/setter, 파이썬클래스 매직 활용들)
고객요청: “학교이름/수헙번호/등급백분위(누락)” 나오게하는
설계
아이템관리, 아이템 두개의 클래스를 1:다 관계로 만들고
아이템관리에
- 아이템의 점수에따른 정렬기능 필요
- 출력기능추가
아이템에
- 수험번호/학교/국/영/수 값저장
아이템관리, 아이템 클레스에 기능요구사항을 적절히 배분하세요
테스트로 사용할 10개정도의 아이템을 먼저 정의한후에 위설계한 내용을 하나씩 코드로 변환 /테스트하면서 구현합니다
일단 한 가지 이해 안가는 부분이..
if self.__engScore>=90:
self.__engScore= '1등급'
이런 식의 문장이 보이는데..
self.__engScore 의 자료형 뭔가요? int? string?
파이썬은 이런 거 구분하지 않는 건가요?? 잘 몰라서..
자료형이 막 혼용되고 있네요.
만약 혼용이 된다고 하더라도. 나중에 스트링을 정수와 비교하는 상황이 생길 듯 한데요.