Question: Please complete the following function copyStoG( G, S) so that the following program would produce the correct output as shown below. Please enter only the

Please complete the following function copyStoG( G, S) so that the following program would produce the correct output as shown below. Please enter only the code for copyStoG( G, S) function as your answer to this problem.

# Python program

def show( G ): # show the 3X3 game board G

for r in range(0, 2+1): # r: 0,1,2

for c in range(0, 2+1): # c: 0,1,2

print( G[r][c],end="" ) # same line

print( ) # end of show ( G ) # end this line

def copyStoG( G, S ): # G is 3x3 board, S is string of 9 characters

# copy 9 chars from string S into G of 3x3 board

i = 0 # string index 0,1, ... ,8

# ENTER YOUR CODE HERE for this function - - - - - - - - - - -

# Warning: If you copy your code from Visual Studio IDE into here, those

# indentations will be lost. You must put those indentations back, otherwise

# your code would have severe syntax errors.

# - - - - - - - - - - - - - - -

# end of createG( G, S)

# MAIN PROGRAM:You must not change any of the following code.

O = 'O'

X = 'X'

G = [ [X,X,X], [X,X,X], [X,X,X] ] # G is a game board of 3x3 array or list

S1 = "XXXXXXXXX"

S2 = "OOOOOOOOO"

S3 = "OXOOXOXOX"

S4 = "XXOOOXXOX"

copyStoG( G, S1) # copy S (a string of 9 characters) into G board of 3x3

print("Game board for S1 \"" + S1 + "\" is as follows:")

show( G ) # print G game board of 3x3

copyStoG( G, S2) #

print("Game board for S2 \"" + S2 + "\" is as follows:")

show( G ) # print G game board of 3x3

copyStoG( G, S3) #

print("Game board for S3 \"" + S3 + "\" is as follows:")

show( G ) # print G game board of 3x3

copyStoG( G, S4) #

print("Game board for S4 \"" + S4 + "\" is as follows:")

show( G ) # print G game board of 3x3

# End of MAIN PROGRAM =====================.

The output of the above program (when completed properly) should be as follows:

Game board for S1 "XXXXXXXXX" is as follows:

XXX

XXX

XXX

Game board for S2 "OOOOOOOOO" is as follows:

OOO

OOO

OOO

Game board for S3 "OXOOXOXOX" is as follows:

OXO

OXO

XOX

Game board for S4 "XXOOOXXOX" is as follows:

XXO

OOX

XOX

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!