<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ##應用:放家具 ### 代碼實現 ~~~ # 定義一個Park類 class Home: def __init__(self, area): self.area = area #房間剩余的可用面積 # self.light = 'on' #燈默認是亮的 self.containsItem = [] def __str__(self): msg = "當前房間可用面積為:" + str(self.area) if len(self.containsItem) > 0: msg = msg + " 容納的物品有: " for temp in self.containsItem: msg = msg + temp.getName() + ", " msg = msg.strip(", ") return msg # 容納物品 def accommodateItem(self,item): # 如果可用面積大于物品的占用面積 needArea = item.getUsedArea() if self.area > needArea: self.containsItem.append(item) self.area -= needArea print("ok:已經存放到房間中") else: print("err:房間可用面積為:{}但是當前要存放的物品需要的面積為{}".format(self.area, needArea)) # 定義bed類 class Bed: def __init__(self,area,name = '床'): self.name = name self.area = area def __str__(self): msg = '床的面積為:' + str(self.area) return msg # 獲取床的占用面積 def getUsedArea(self): return self.area def getName(self): return self.name # 創建一個新家對象 newHome = Home(100)#100平米 print(newHome) # 創建一個床對象 newBed = Bed(20) print(newBed) # 把床安放到家里 newHome.accommodateItem(newBed) print(newHome) # 創建一個床對象 newBed2 = Bed(30,'席夢思') print(newBed2) # 把床安放到家里 newHome.accommodateItem(newBed2) print(newHome) ~~~ :-: ![](https://img.kancloud.cn/5a/78/5a7888087941cfadf3d2bf6b8d3c438b_419x198.png) #### 總結: * 如果一個對象與另外一個對象有一定的關系,那么一個對象可用是另外一個對象的屬性 #### 思維升華: * 添加“開、關”燈,讓房間、床一起亮、滅
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看