728x90
반응형
SW Expert Academy에서 학습용으로 문제를 가져왔습니다. 문제가 될 시 수정, 삭제하겠습니다.
https://swexpertacademy.com/main/main.do
문제 : 다음의 결과와 같이 국어, 영어, 수학 점수를 입력받아 합계를 구하는 객체지향 코드를 작성하십시오.
이 때 학생 클래스의 객체는 객체 생성 시 국어, 영어, 수학 점수를 저장하며, 총점을 구하는 메서드를 제공합니다.
input
89, 90, 100
output
국어, 영어, 수학의 총점: 279
code
class student:
def __init__(self, kor, eng, math):
self.__kor=kor
self.__eng=eng
self.__math=math
@property
def kor(self):
return self.__kor
@property
def eng(self):
return self.__eng
@property
def math(self):
return self.__math
def total_score(self):
return "국어, 영어, 수학의 총점: {0}".format(self.__kor + self.__eng + self.__math)
students=list(map(int,input().split(',')))
students_list=student(students[0], students[1], students[2])
print(students_list.total_score())
필드값인 국어, 영어, 수학을 생성해줍니다. 일반적으로 데이터를 읽어주는 메서드를 getter(게터), 데이터를 변경해주는 메서드를 setter(세터)라고 합니다. property로 getter메서드로 국어, 영어 수학을 읽고 students_list에 students에서 각각에 대응하는 점수를 입력받은 다음 마지막으로 만들어두었던 total_score로 총 합계를 계산해주면 됩니다.
728x90
반응형
'Programming > SWEA' 카테고리의 다른 글
[SWEA 6217].[파이썬 프로그래밍 기초(2) 파이썬의 기본 응용] 5. 객체지향 3 (0) | 2021.07.29 |
---|---|
[SWEA 6208].[파이썬 프로그래밍 기초(2) 파이썬의 기본 응용] 5. 객체지향 2 (0) | 2021.07.29 |
[SWEA 6248].[파이썬 프로그래밍 기초(2) 파이썬의 기본 응용] 4. 문자열 7 (0) | 2021.07.29 |
[SWEA 6243].[파이썬 프로그래밍 기초(2) 파이썬의 기본 응용] 4. 문자열 5 (0) | 2021.07.28 |
[SWEA 6678].[파이썬 프로그래밍 기초(2) 파이썬의 기본 응용] 4. 문자열 4 (0) | 2021.07.28 |