Python 入門指南 5.0
exercise2601.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 27 28 29 30 31 32 33 34 35 | # 引入 Point 定義 from exercise1810 import Point # 引入 Lion 定義 from exercise1812 import Lion # 執行部分 if __name__ == '__main__': # 建立獅子物件 lion = Lion(Point(1,1), "Red") # 設定地圖 world = [["口", "口", "口", "口"], ["口", "口", "口", "口"], ["口", "口", "口", "口"], ["口", "口", "口", "口"]] # 取得獅子座標 x = lion.point.x y = lion.point.y # 在地圖上印出獅子 i = 0 while i < len(world): j = 0 while j < len(world[i]): if i == y and j == x: print(lion, end=" ") else: print(world[i][j], end=" ") j += 1 print() i += 1 # 檔名: exercise2601.py # 說明:《Python入門指南》的練習 # 網站: http://kaiching.org # 作者: 張凱慶 # 時間: 2023 年 10 月 |