-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()
非常感谢,它非常有帮助。 –