#4p: Codding in Python {2-player:Tic Tak Toe}
print('Player 1 will start first.')
ply1=str(input('Enter name player 1: '))
ply2=str(input('Enter name player 2: '))
aq=ply1
bq=ply2
def game():
arow=['a1','a2','a3']
brow=['b1','b2','b3']
crow=['c1','c2','c3']
a='a1'
b='a2'
c='a3'
d='b1'
e='b2'
f='b3'
g='c1'
h='c2'
i='c3'
avai=[a,b,c,d,e,f,g,h,i]
total=[arow,brow,crow]
player1=[]
m=player1
player2=[]
n=player2
def matrix():
for anya in (total):
for avya in (anya):
print(avya,' ',end='')
print()
matrix()
for main in range(5):
if main<5:
shit1=ply1,'Where to hit: '
for ww in range(10):
mark=str(input(shit1))
if mark in (avai):
for az in (total):
if mark in (az):
x=az.index(mark)
az.remove(mark)
az.insert(x,'**')
player1.append(mark)
avai.remove(mark)
matrix()
break
else:
print('Incorect or alreay in use.')
if a in(player1):
if b in (player1):
if c in (player1):
print(aq,' wins.')
break
if d in(player1):
if e in (player1):
if f in (player1):
print(aq,' wins.')
break
if g in(player1):
if h in (player1):
if i in (player1):
print(aq,' wins.')
break
if c in(player1):
if i in (player1):
if f in (player1):
print(aq,' wins.')
break
if b in(player1):
if e in (player1):
if h in (player1):
print(aq,' wins.')
break
if a in(player1):
if d in (player1):
if g in (player1):
print(aq,' wins.')
break
if a in(player1):
if e in (player1):
if i in (player1):
print(aq,' wins.')
break
if c in(player1):
if e in (player1):
if g in (player1):
print(aq,' wins.')
break
if main<4:
shit2=ply2,'Where to hit: '
for wwe in range(10):
mark1=str(input(shit2))
if mark1 in (avai):
for az1 in (total):
if mark1 in (az1):
xq=az1.index(mark1)
az1.remove(mark1)
az1.insert(xq,'##')
player2.append(mark1)
avai.remove(mark1)
matrix()
break
else:
print('Incorect or alreay in use.')
if a in(player2):
if b in (player2):
if c in (player2):
print(bq,' wins.')
break
if d in(player2):
if e in (player2):
if f in (player2):
print(bq,' wins.')
break
if g in(player2):
if h in (player2):
if i in (player2):
print(bq,' wins.')
break
if c in(player2):
if i in (player2):
if f in (player2):
print(bq,' wins.')
break
if b in(player2):
if e in (player2):
if h in (player2):
print(bq,' wins.')
break
if a in(player2):
if d in (player2):
if g in (player2):
print(bq,' wins.')
break
if a in(player2):
if e in (player2):
if i in (player2):
print(bq,' wins.')
break
if c in(player2):
if e in (player2):
if g in (player2):
print(bq,' wins.')
break
if len(player1)==5 and len(player2)==4:
print('Match tied!!')
game()
while 1==1:
print('Want to play again ',aq,' and ',bq,' ?')
qwerty=int(input('Enter 1 for yes or 2 for no: '))
if qwerty==1:
game()
else:
print('Thank you for playing.')
break
Download CODES here.
Comments