From c392320f92a8cf0f39d5c5bd90b2ae83c412e9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=83=ED=97=88=EB=B8=8C=EB=8B=89=EB=84=A4=EC=9E=84?= <깃허브이메일> Date: Mon, 4 May 2020 16:40:43 +0900 Subject: [PATCH 1/2] =?UTF-8?q?(=EC=9C=A4=EC=86=8C=EC=98=81)=204=EC=A3=BC?= =?UTF-8?q?=EC=B0=A8=20=EA=B3=BC=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assignment 4/Assignment4-1-1.py" | 24 ++++++++ .../Assignment 4/Assignment4-1.py" | 50 +++++++++++++++++ .../Assignment 4/Assignment4-2.py" | 55 +++++++++++++++++++ .../Assignment 4/python-study-8th" | 1 + 4 files changed, 130 insertions(+) create mode 100644 "\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-1-1.py" create mode 100644 "\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-1.py" create mode 100644 "\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-2.py" create mode 160000 "\354\234\244\354\206\214\354\230\201/Assignment 4/python-study-8th" diff --git "a/\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-1-1.py" "b/\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-1-1.py" new file mode 100644 index 0000000..139ae1a --- /dev/null +++ "b/\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-1-1.py" @@ -0,0 +1,24 @@ +# class 과제 : 계산기를 class로 바꾸기 2번 방법(과제 예시랑 같은 방법으로 print) + +class calculator : + def sum(self, num1, num2): # sum 메서드를 만들어준다. # def __init__ 빼고 def sum()에 인수 다 넣어준다. + return num1 + num2 + def sub(self, num1, num2): + return num1 - num2 + def mul(self, num1, num2): + return num1 * num2 + def div(self, num1, num2): + return num1 / num2 + def double_mul(self, num1, num2): + return num1 ** num2 + def remainder(self, num1, num2): + return num1 % num2 + +cal = calculator() # 객체 생성 + +print(cal.sum(1, 3)) +print(cal.sub(6, 4)) +print(cal.mul(9, 3)) +print(cal.div(18, 2)) +print(cal.double_mul(99, 4)) +print(cal.remainder(6847, 234)) \ No newline at end of file diff --git "a/\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-1.py" "b/\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-1.py" new file mode 100644 index 0000000..cf1e0ee --- /dev/null +++ "b/\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-1.py" @@ -0,0 +1,50 @@ +# class 과제 : 계산기를 class로 바꾸기 1번 방법 + +class calculator : + def __init__(self, num1, num2): # __init__메서드 + self.num1 = num1 + self.num2 = num2 + + def sum(self): # sum 메서드를 만들어준다. #언제는 self만 들어가고, 언제는 객체가 다 들어가고? + return self.num1 + self.num2 + def sub(self): + return self.num1 - self.num2 + def mul(self): + return self.num1 * self.num2 + def div(self): + return self.num1 / self.num2 + def double_mul(self): + return self.num1 ** self.num2 + def remainder(self): + return self.num1 % self.num2 + +# cal = calculator() +# print(cal.sum(10, 2)) # 배운 건 이건데(과제 예시문도) + +cal = calculator(10, 2) # num1 = 10, num2 = 2 + +print(cal.sum()) +print(cal.sub()) +print(cal.mul()) +print(cal.div()) +print(cal.double_mul()) +print(cal.remainder()) # 계산기에선 왜 거꾸로 써야 실행될까 + +cal2 = calculator(5, 9) +print(cal2.sum()) +print(cal2.sub()) +print(cal2.mul()) + +# print(cal.sum(1, 2)) 이 형태로 왜 안되는걸까 + +# cal2 = calculator() +# print(cal2.sum(1,2)) -> num1이랑 num2를 잃어버렸대 이걸 알려줘야겠다 + +# cal2 = calculator(self.num1, self.num2) -> 이건 self가 define되지 않았대 +# print(cal2.sum(1,2)) + +# cal2(self.num1, self.num2) = calculator() -> 이건 그냥 함수가 이상하대 +# print(cal2.sum(1,2)) + +cal3 = calculator() +print(cal3.sum(1,2)) \ No newline at end of file diff --git "a/\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-2.py" "b/\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-2.py" new file mode 100644 index 0000000..9d7451a --- /dev/null +++ "b/\354\234\244\354\206\214\354\230\201/Assignment 4/Assignment4-2.py" @@ -0,0 +1,55 @@ +# class 과제 2 : 상속받은 calss 만들기(과제 1, 1번방법에서 이어함) + +class calculator : + def __init__(self, num1, num2): # __init__메서드 + self.num1 = num1 + self.num2 = num2 + + def sum(self): # sum 메서드를 만들어준다. + return self.num1 + self.num2 + def sub(self): + return self.num1 - self.num2 + def mul(self): + return self.num1 * self.num2 + def div(self): + return self.num1 / self.num2 + def double_mul(self): + return self.num1 ** self.num2 + def remainder(self): + return self.num1 % self.num2 + +cal = calculator(10, 2) # num1 = 10, num2 = 2 + +print(cal.sum()) +print(cal.sub()) +print(cal.mul()) +print(cal.div()) +print(cal.double_mul()) +print(cal.remainder()) + +# 여기까지는 과제1과 동일 + +class can_div_zero(calculator): # 상속했다 + + def div(self): + if self.num2 == 0: + return "0으로는 나눌 수 없습니다" + else: + return self.num1 / self.num2 + + def remainder(self): + if self.num2 == 0: + return "0으로는 나눌 수 없습니다" + else: + return self.num1 / self.num2 + +can_div = can_div_zero(5, 0) # num1 = 5, num2 = 0 + +print(can_div.sum()) +print(can_div.sub()) +print(can_div.div()) +print(can_div.double_mul()) +print(can_div.remainder()) # 얘도 나누기 결과값이라 if 해줘야 함! + + + diff --git "a/\354\234\244\354\206\214\354\230\201/Assignment 4/python-study-8th" "b/\354\234\244\354\206\214\354\230\201/Assignment 4/python-study-8th" new file mode 160000 index 0000000..ac754d5 --- /dev/null +++ "b/\354\234\244\354\206\214\354\230\201/Assignment 4/python-study-8th" @@ -0,0 +1 @@ +Subproject commit ac754d5ba73c85cdbbcecaff363e1a5e918410dd From 82156e96cd59bf15f477ad99854b6a8ef1e8939e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=83=ED=97=88=EB=B8=8C=EB=8B=89=EB=84=A4=EC=9E=84?= <깃허브이메일> Date: Mon, 4 May 2020 16:50:42 +0900 Subject: [PATCH 2/2] =?UTF-8?q?(=EC=9C=A4=EC=86=8C=EC=98=81)=204=EC=A3=BC?= =?UTF-8?q?=EC=B0=A8=20=EA=B3=BC=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assignment 4/python-study-8th" | 1 - 1 file changed, 1 deletion(-) delete mode 160000 "\354\234\244\354\206\214\354\230\201/Assignment 4/python-study-8th" diff --git "a/\354\234\244\354\206\214\354\230\201/Assignment 4/python-study-8th" "b/\354\234\244\354\206\214\354\230\201/Assignment 4/python-study-8th" deleted file mode 160000 index ac754d5..0000000 --- "a/\354\234\244\354\206\214\354\230\201/Assignment 4/python-study-8th" +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ac754d5ba73c85cdbbcecaff363e1a5e918410dd