PYTHON/파이썬 코딩 도장
파이썬 코딩 도장 UNIT 36, 37 심사문제
GaeGim
2022. 7. 30. 12:27
반응형
36.9 심사문제: 다중 상속 사용하기
class Animals:
def eat(self):
print('먹다')
class Wing:
def flap(self):
print('파닥거리다')
class Bird(Animals, Wing):
def fly():
print('날다')
37.3 심사문제: 두 점 사이의 거리 구하기
import math
class Point2D:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
length = 0.0
p = [Point2D(), Point2D(), Point2D(), Point2D()]
p[0].x, p[0].y, p[1].x, p[1].y, p[2].x, p[2].y, p[3].x, p[3].y = map(int, input().split())
#case1 : 점들이 한 선 위에 있을 때
#첫 점과 마지막 점으로만 구한다
length = math.sqrt((p[3].y - p[0].y)**2 + (p[3].x-p[0].x)**2)
print(length)
#case2 : 점들이 여러 곳에 있을 때
for i in range(len(p)-1):
x_l = p[i+1].x - p[i].y
y_l = p[i+1].y - p[i].y
length += math.sqrt(math.pow(x_l, 2) + math.pow(y_l, 2))
print(length)
반응형