Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions TicTacToe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Tic Tac Toe

import random
import sys

def get_input():
if sys.version_info >= (3, 0):
return input()
else:
return raw_input()

def drawBoard(board):
# This function prints out the board that it was passed.
Expand All @@ -18,7 +25,7 @@ def inputPlayerLetter():
letter = ''
while not (letter == 'X' or letter == 'O'):
print('Do you want to be X or O?')
letter = input().upper()
letter = get_input().upper()

# the first element in the tuple is the player's letter, the second is the computer's letter.
if letter == 'X':
Expand All @@ -36,7 +43,7 @@ def whoGoesFirst():
def playAgain():
# This function returns True if the player wants to play again, otherwise it returns False.
print('Do you want to play again? (yes or no)')
return input().lower().startswith('y')
return get_input().lower().startswith('y')

def makeMove(board, letter, move):
if isSpaceFree(board,move):
Expand Down Expand Up @@ -74,7 +81,7 @@ def getPlayerMove(board):
move = ' '
while move not in '1 2 3 4 5 6 7 8 9'.split() or not isSpaceFree(board, int(move)):
print('What is your next move? (1-9)')
move = input()
move = get_input()
return int(move)

def chooseRandomMoveFromList(board, movesList):
Expand Down Expand Up @@ -186,4 +193,4 @@ def main():
break

if __name__ == "__main__":
main()
main()