(Python) Why doesn't my method object execute when I call it after my class definition? -
when try run program in idle (the text editor i'm using @ moment, notepad ++ said indentation error , don't know why) code in __init__
, shows it's been created object. line after tried use main method , doesn't anything. changed different method didn't work either. here's program:
import sys class main: def __init__(self): winx = false wino = false turn = 'x' lastturn = 'x' a, b, c, d, e, f, g, h, = ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' poslist = [] poslist.append(a) poslist.append(b) poslist.append(c) poslist.append(d) poslist.append(e) poslist.append(f) poslist.append(g) poslist.append(h) poslist.append(i) self.board = '+---+---+---+\n| ' + poslist[0] +' | '+ poslist[1] +' | '+ poslist[2] +' |\n+---+---+---+\n| '+ poslist[3] +' | '+ poslist[4] +' | '+ poslist[5] +' |\n+---+---+---+\n| '+ poslist[6] +' | '+ poslist[7] +' | '+ poslist[8] +' |\n+---+---+---+' print self.board def updateturn(self): if lastturn == 'x': turn == 'o' elif lastturn == 'o': turn == 'x' lastturn = turn def winchecker(self): if , b , c == 'x' or , d , g == 'x' or , e , == 'x' or g , e , c == 'x' or g , h , == 'x' or c , f , == 'x': winx = true if , b , c == 'o' or , d , g == 'o' or , e , == 'o' or g , e , c == 'o' or g , h , == 'o' or c , f , == 'o': wino = true def updateboard(self): print self.board def starter(self): while true: try: = int(input('')) except typeerror: print 'not number, try again.' continue -= 1 poslist[i] = turn self.updateboard self.winchecker if winx == true: print 'x wins!' sys.exit() elif wino == true: print 'o wins!' sys.exit() self.updateturn s = main() s.starter
i (4 days) finished python's own tutorial.
call starter function
s.starter()
and there might logical error while loop below true.
def starter(self): while true: try: = int(input('')) except typeerror: print 'not number, try again.' continue
Comments
Post a Comment