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 ""I need help with a Python problem I need to Finish the else: return ""logic for the winner Also make a separate introduction page (html file 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 ("

") print ("Player " + whogoes + " goes") print ("

") def printRestart(): print ("
") print ("") print ("

") def printCell(cellEntry, cellNumber): if cellEntry == ' ': print ("") else: print ( imageTag(cellEntry) ) def printForm(boardList, whogoes): print ("

") print ("") boardString = ':' boardString = boardString.join(boardList) print ("") print ("") # /t == tab to make the output html look better for row in range(0,3): print ("\t") print ("\t\t") print ("\t\t") print ("\t\t") print ("") print ("
") printCell(boardList[0 + row*3], 0 + row*3) print ("\t\t") printCell(boardList[1 + row*3], 1 + row*3) print ("\t\t") printCell(boardList[2 + row*3], 2 + row*3) print ("\t

") 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!