11# Tic Tac Toe
22
33import random
4+ import sys
5+
6+ def get_input ():
7+ if sys .version_info >= (3 , 0 ):
8+ return input ()
9+ else :
10+ return raw_input ()
411
512def drawBoard (board ):
613 # This function prints out the board that it was passed.
@@ -18,7 +25,7 @@ def inputPlayerLetter():
1825 letter = ''
1926 while not (letter == 'X' or letter == 'O' ):
2027 print ('Do you want to be X or O?' )
21- letter = input ().upper ()
28+ letter = get_input ().upper ()
2229
2330 # the first element in the tuple is the player's letter, the second is the computer's letter.
2431 if letter == 'X' :
@@ -36,7 +43,7 @@ def whoGoesFirst():
3643def playAgain ():
3744 # This function returns True if the player wants to play again, otherwise it returns False.
3845 print ('Do you want to play again? (yes or no)' )
39- return input ().lower ().startswith ('y' )
46+ return get_input ().lower ().startswith ('y' )
4047
4148def makeMove (board , letter , move ):
4249 if isSpaceFree (board ,move ):
@@ -74,7 +81,7 @@ def getPlayerMove(board):
7481 move = ' '
7582 while move not in '1 2 3 4 5 6 7 8 9' .split () or not isSpaceFree (board , int (move )):
7683 print ('What is your next move? (1-9)' )
77- move = input ()
84+ move = get_input ()
7885 return int (move )
7986
8087def chooseRandomMoveFromList (board , movesList ):
@@ -186,4 +193,4 @@ def main():
186193 break
187194
188195if __name__ == "__main__" :
189- main ()
196+ main ()
0 commit comments