Python 入門指南 5.0
exercise1504.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 | # 引入 Point 定義
from exercise1501 import Point
# 引入 Animal 定義
from exercise1502 import Animal
# 定義 Lion
class Lion(Animal):
def __init__(self, p, c):
super().__init__(p, "獅", c)
self.food = ["獅", "虎", "豹", "狼", "狗", "貓", "鼠"]
# 建立 Lion 物件
lion = Lion(Point(3,3), "Blue")
# 印出獅子所在座標
print("動物" + lion.name + "在" + str(lion.point))
# 印出獅子可以吃掉的棋子種類
print("動物" + lion.name + "可以吃", end="")
for i in lion.food:
print(i, end="")
print()
# 檔名: exercise1504.py
# 說明:《Python入門指南》的練習
# 網站: http://kaiching.org
# 作者: 張凱慶
# 時間: 2023 年 9 月
|