Python 入門指南 5.0

exercise1506.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

# 定義 Leopard
class Leopard(Animal):
    def __init__(self, p, c):
        super().__init__(p, "豹", c)
        self.food = ["豹", "狼", "狗", "貓", "鼠"]

# 建立 Leopard 物件
leopard = Leopard(Point(3,3), "Blue")
# 印出豹所在座標
print("動物" + leopard.name + "在" + str(leopard.point))
# 印出豹可以吃掉的棋子種類
print("動物" + leopard.name + "可以吃", end="")
for i in leopard.food:
    print(i, end="")
print()

# 檔名: exercise1506.py
# 說明:《Python入門指南》的練習
# 網站: http://kaiching.org
# 作者: 張凱慶
# 時間: 2023 年 9 月

回到練習題目
上一頁 exercise1505.py
回 Python 入門指南 5.0 首頁
下一頁 exercise1507.py
回 Python 教材首頁
回程式語言教材首頁