Python 入門指南 5.0

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

# 定義 Mouse
class Mouse(Animal):
    def __init__(self, p, c):
        super().__init__(p, "鼠", c)
        self.food = ["鼠", "象"]

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

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

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