Question: I need help with a Python problem I need to Finish the logic for the winner Also make a separate introduction page (html file is
I need help with a Python problem
I need to Finish the logic for the winner
Also make a separate introduction page (html file is ok) that asks for the names of the two players, then instead of saying X Goes, say the name of the player.
The picture of the X and O will be next to the code
Here is the code:
#!/usr/local/bin/python3.5 import cgi, cgitb cgitb.enable() def imageTag(string): if string=='X': return ""else: return ""
def threeInARow(tttBoard, p1, p2, p3): # 0 1 2 # 3 4 5 # 6 7 8 if tttBoard[p1] == tttBoard[p2] and \ tttBoard[p2] == tttBoard[p3] and \ tttBoard[p1] != ' ': return tttBoard[p1] return None def findWinner(tttBoard): if threeInARow(tttBoard, 6, 7, 8) is not None: return threeInARow(tttBoard, 6, 7, 8) return None def printWhoGoes(whogoes): print ("
") def printRestart(): print (" ") print ("Player " + whogoes + " goes") print ("
") def printCell(cellEntry, cellNumber): if cellEntry == ' ': print ("") else: print ( imageTag(cellEntry) ) def printForm(boardList, whogoes): print ("
") print ("Content-type: text/html ") print ("Version 0.00a") tttForm = cgi.FieldStorage() cell = tttForm.getvalue('cell') if cell is None: # (re)start the game tttBoard = [' ',' ', ' ', \ ' ',' ', ' ', \ ' ',' ', ' ' ] whogoes = 'X' else: tttString = tttForm.getvalue('tttString') whogoes = tttForm.getvalue('whogoes') tttBoard = tttString.split(':') tttBoard[ int(cell) ] = whogoes if whogoes=='X': whogoes='O' else: whogoes='X' winner = findWinner(tttBoard) if winner is None: printWhoGoes(whogoes) printForm(tttBoard, whogoes) else: print (winner) print ("is the winner") printRestart()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts

else: return ""
def threeInARow(tttBoard, p1, p2, p3): # 0 1 2 # 3 4 5 # 6 7 8 if tttBoard[p1] == tttBoard[p2] and \ tttBoard[p2] == tttBoard[p3] and \ tttBoard[p1] != ' ': return tttBoard[p1] return None def findWinner(tttBoard): if threeInARow(tttBoard, 6, 7, 8) is not None: return threeInARow(tttBoard, 6, 7, 8) return None def printWhoGoes(whogoes): print ("