-1
我試圖做一個井字遊戲,所以我建立了董事會,其中比賽將是,但我得到這個錯誤:實例方法提高AttributeError的,即使屬性被定義
Traceback (most recent call last):
File "python", line 18, in <module>
File "python", line 10, in display
AttributeError: 'Board' object has no attribute 'cells
不能想出問題的原因
import os #try to import the clode to the operating system, use import
os.system('clear')
# first: Build the board
class Board(): #use class as a templete to create the object, in this case the board
def _init_(self):
self.cells = [' ', ' ', ' ' , ' ', ' ', ' ' , ' ', ' ', ' '] #will use self to define the method, in this case the board cells
def display(self):
print ('%s | %s | %s' %(self.cells[1] , self.cells[2] , self.cells[3]))
print ('_________')
print ('%s | %s | %s' %(self.cells[4] , self.cells[5] , self.cells[6]))
print ('_________')
print ('%s | %s | %s' %(self.cells[7] , self.cells[8] , self.cells[9]))
print ('_________')
board = Board()
board.display()
非常感謝,它非常有幫助。 –