결과
코드
복사코드
class shape:
def __init__(self,x,y):
self.x=x
self.y=y
def area(self):
print("계산할 수 없음!")
def perimeter(self):
print("계산할 수 없음!")
class rectangle(shape):
def __init__(self,x,y,w,h):
super().__init__(x,y)
self.w=w
self.h=h
def area(self):
return self.w*self.h
def perimeter(self):
return 2*(self.w+self.h)
while(1):
n=int(input('선택 1)면적 2)둘레 3)종료 : '))
if n==1:
w1, h1 = map(int, input('가로, 세로 입력 : ').split())
r1=rectangle(0,0,w1,h1)
print("사각형의 면적 : ",r1.area())
print('\n')
elif n==2:
w2, h2 = map(int, input('가로, 세로 입력 : ').split())
r2=rectangle(0,0,w2,h2)
print("사각형의 둘레 : ",r2.perimeter())
print('\n')
elif n==3:
print("프로그램 종료")
break
else:
print("다시 선택!\n")
'Python > python 개발' 카테고리의 다른 글
[파이썬/python] 정수 확인 예외처리 (0) | 2022.01.27 |
---|---|
[파이썬/python] 직원 월급 및 보너스 작성 (0) | 2022.01.26 |
[파이썬/python] UP & DOWN 게임 tk (0) | 2022.01.23 |
[파이썬/python] 계산기2 tk (0) | 2022.01.22 |
[파이썬/python] 타이머 tk (0) | 2022.01.20 |