Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

So young #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions 윤소영/Assignment 4/Assignment4-1-1.py
Original file line number Diff line number Diff line change
@@ -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))
50 changes: 50 additions & 0 deletions 윤소영/Assignment 4/Assignment4-1.py
Original file line number Diff line number Diff line change
@@ -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))
55 changes: 55 additions & 0 deletions 윤소영/Assignment 4/Assignment4-2.py
Original file line number Diff line number Diff line change
@@ -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 해줘야 함!