• 코드:
​x
 
1
import math
2
​
3
class Animal:
4
    def __init__(self, age, height, color, xpos, ypos):
5
        self.age = age
6
        self.height = height
7
        self.color = color
8
        self.xposition = xpos
9
        self.yposition = ypos
10
        self.velocity = 0
11
​
12
    def sound(self):
13
        pass
14
​
15
class Horse(Animal):
16
    def __init__(self, age, height, color, xpos, ypos):
17
        Animal.__init__(self, age, height, color, xpos, ypos)
18
​
19
    def sound(self):
20
        print('Neigh')
21
​
22
    def run(self, xdistance, ydistance, time):
23
        self.xposition += xdistance
24
        self.yposition += ydistance
25
        total_distance = math.sqrt((xdistance + xdistance) * (ydistance + ydistance))
26
        self.velocity = total_distance/time
27
​
28
class Dog(Animal):
29
    def __init__(self, age, height, color, xpos, ypos):
30
        Animal.__init__(self, age, height, color, xpos, ypos)
31
​
32
    def sound(self):
33
        print('Bow-Wow')
34
​
35
if __name__ == '__main__':
36
    danbi = Horse(5, 160, 'brown', 0, 0)
37
    choco = Dog(10, 100, 'black', 50, 30)
38
    danbi.sound()
39
    choco.sound()
표준입력 & 실행옵션