board = [0,1,2,3,4,5,6,7,8] def show(): print board[0],'|',board[1],'|',board[2] print '----------' print board[3],'|',board[4],'|',board[5] print '----------' print board[6],'|',board[7],'|',board[8] def checkLine(char,spot1,spot2,spot3): if board[spot1] == char and board[spot2] == char and board[spot3] == char: return True def checkAll(char): if checkLine(char,0,1,2) == true or checkLine(char,3,4,5) == true or checkLine(char,6,7,8) == true or checkLine(char,0,3,6) == true or checkLine(char,1,4,7) == true or checkLine(char,2,5,8) == true or checkLine(char,0,4,8) == true or checkLine(char,2,4,6) == true: return True while True: input = raw_input("Select a spot: ") input = int(input) if board[input] != 'x' and board [input] != 'o': board[input] = 'x' if checkAll(x) == True: print "~~ X wins ~~" break; counter = 0 while True: opponent = counter if board[opponent] != 'o' and board[opponent] != 'x': board[opponent]='o' if checkAll(o) == True: print"~~ O wins ~~" break; break; counter = counter+1 else: print 'This spot is taken!' show()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question