Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
shuru17
#python 3.5.2 print("Tic tac toe") board = ["-", "-", "-", "-", "-", "-", "-", "-", "-"] def disp(board): print(board[0] + " | " + board[1] + " | " + board[2] + " 1 | 2 | 3") print(board[3] + " | " + board[4] + " | " + board[5] + " 4 | 5 | 6") print(board[6] + " | " + board[7] + " | " + board[8] + " 7 | 8 | 9") used=[] def check(board): if board[0]=="x" and board[3]=="x" and board[6]=="x": print("X won") exit() elif board[0]=="x" and board[1]=="x" and board[2]=="x": print("X won") exit() elif board[1]=="x" and board[4]=="x" and board[7]=="x": print("X won") exit() elif board[0]=="x" and board[4]=="x" and board[8]=="x": print("X won") exit() elif board[6]=="x" and board[7]=="x" and board[8]=="x": print("X won") exit() elif board[2]=="x" and board[5]=="x" and board[8]=="x": print("X won") exit() elif board[3]=="x" and board[4]=="x" and board[5]=="x": print("X won") exit() elif board[6]=="x" and board[4]=="x" and board[2]=="x": print("X won") exit() else: print("player x you are playing nice") def check1(board): if board[0]=="o" and board[3]=="o" and board[6]=="o": print("o won") exit() elif board[0]=="o" and board[1]=="o" and board[2]=="o": print("o won") exit() elif board[0]=="o" and board[4]=="o" and board[8]=="o": print("o won") exit() elif board[6]=="o" and board[7]=="o" and board[8]=="o": print("o won") exit() elif board[2]=="o" and board[5]=="o" and board[8]=="o": print("o won") exit() elif board[1]=="o" and board[4]=="o" and board[7]=="o": print("o won") exit() elif board[3]=="o" and board[4]=="o" and board[5]=="o": print("o won") exit() elif board[6]=="o" and board[4]=="o" and board[2]=="o": print("o won") exit() else: print("player o you are playing nice") print("X's Turn.") print("Choose a position from 1-9\n") pos=int(input()) used.append(pos) def ek(board,disp): if pos==1: board[0]="x" disp(board) elif pos==2: board[1]="x" disp(board) elif pos==3: board[2]="x" disp(board) elif pos==4: board[3]="x" disp(board) elif pos==5: board[4]="x" disp(board) elif pos==6: board[5]="x" disp(board) elif pos==7: board[6]="x" disp(board) elif pos==8: board[7]="x" disp(board) elif pos==9: board[8]="x" disp(board) else: print("pls insert between 1 to 9") ek(board,disp) print("Now O's turn.") print("Choose a position from 1-9\n") poso=int(input()) for items in used: if poso!=items: used.append(poso) elif poso==items: print("choose another position") def do(board,disp): if poso==1: board[0]="o" disp(board) elif poso==2: board[1]="o" disp(board) elif poso==3: board[2]="o" disp(board) elif poso==4: board[3]="o" disp(board) elif poso==5: board[4]="o" disp(board) elif poso==6: board[5]="o" disp(board) elif poso==7: board[6]="o" disp(board) elif poso==8: board[7]="o" disp(board) elif poso==9: board[8]="o" disp(board) else: print("pls insert between 1 to 9") do(board,disp) print("Now X's turn.") print("Choose a position from 1-9\n") posx=int(input()) used.append(posx) pos=posx ek(board,disp) print("Now O's turn.") print("Choose a position from 1-9\n") posoo=int(input()) used.append(posoo) poso=posoo do(board,disp) print("Now X's turn.") print("Choose a position from 1-9\n") posxx=int(input()) used.append(posxx) pos=posxx ek(board,disp) check(board) print("Now O's turn.") print("Choose a position from 1-9\n") posooo=int(input()) used.append(posooo) poso=posooo do(board,disp) check1(board) print("Now X's turn.") print("Choose a position from 1-9\n") posxxx=int(input()) used.append(posxxx) pos=posxxx ek(board,disp) check(board) print("Now O's turn.") print("Choose a position from 1-9\n") posoooo=int(input()) used.append(posoooo) poso=posoooo do(board,disp) check1(board) print("Now X's turn.") print("Choose a position from 1-9\n") posxxxx=int(input()) used.append(posxxxx) pos=posxxxx ek(board,disp) check(board) for items in used: print(items)
run
|
edit
|
history
|
help
0
Lesson5-
Homework exercise
Overview
gauss elimination determinant calculator
Python
salarysms
func1
http://rextester.com/HYVN80193
5
restraunt score