;
you dont need in python but is needed in gsc coding this could give you alot of bad syntax
places = {}
def check_place(n):
try:
n = int(float(n))
except ValueError:
return "Unaccepted input"
else:
if places.get(n, 'no'
== 'no':
return n
else:
return "Choose another place"
def winner(notation):
lst = places.values()
if (lst[0:3] == [notation, notation, notation]) or (lst[3:6] == [notation, notation, notation]) or (lst[6:] == [notation, notation, notation]) or (lst[0::4]==[notation, notation, notation]) or (lst[2:7:2] == [notation, notation, notation]) or (lst[0:7:3] == [notation, notation, notation]) or (lst[1:8:3] == [notation, notation, notation]) or (lst[2::3] == [notation, notation, notation]):
return True
else:
return False
def game(pn, order): # u == turn, pn == player notation
print "Player %s's turn" % order
play = check_place(raw_input("Please enter the cell number: "))
if isinstance(play, str):
print play
else:
places[play] = pn
print """
%s | %s | %s
---|---|---
%s | %s | %s
---|---|---
%s | %s | %s
""" % (places.get(1, ' '
,places.get(2, ' '
,places.get(3, ' '
,places.get(4, ' '
,places.get(5,' '
,places.get(6, ' '
,places.get(7, ' '
,places.get(8, ' '
,places.get(9, ' '
)
win = winner(pn)
return win
print """ Each cell has its own number, so:
1 | 2 | 3
---|---|---
4 | 5 | 6
---|---|---
7 | 8 | 9
"""
while True: # To know who X is and who O is.
p1n = raw_input("Please choose, X or O: ")
if len(p1n.strip().lower()) != 1:
print "Please type: X or O"
else:
if (p1n.strip()).lower() == 'o':
print "player 1: O\nplayer 2: X"
p1n = 'O'
p2n = 'X'
break
elif (p1n.strip()).lower() == 'x':
print "player 1: X\nplayer 2: O"
p1n = 'X'
p2n = 'O'
break
else:
print "X or O"
continue
turn = 1
while turn <= 9:
if turn in [1,3,5,7,9]:
c = game(p1n, '1'
if c:
print 'Player 1 wins
'
break
else:
turn += 1
else:
c = game(p2n, '2'
if c:
print 'Player 2 wins
'
break
else:
turn += 1
if len(places) == 9 and c == False:
print "TIE"
raw_input("Press enter to exit...")
Copyright © 2026, NextGenUpdate.
All Rights Reserved.