Cisco_kid
12-12-2011, 08:23 PM
I need some help with this python code:
#If B is a board, printFriendly(B) renders the board B onto the screen as a tic #tac toe board with x's and o's in appropriate positions.
The following Python program prints the board ['x', 'e', 'x', 'x', 'o', 'o', 'o', 'e', 'x']:
x='x'
o='o'
pipe = '|'
space = ' '
print(x,pipe,space,pipe,x)
print("---------")
print(x,pipe,o,pipe,o)
print("---------")
print(o,pipe,space,pipe,x)
This is what I know so far. I need to write the code for the aforementioned contract.
I have tried to fulfil the contract with this code:
def printFriendly(B):
board = [['x','x','o'],['','',''],['','x','o']]
#Output
print ("-------")
for row in board:
print ("|%s|") % ('|'.join(row))
print ("-------")
I continuously get error messages about incorrectly defining "board" as well as incorrect syntax. I have just started programming so I'm not sure what I'm doing wrong.
Any help is greatly appreciated.
Thanks,
Jordan
#If B is a board, printFriendly(B) renders the board B onto the screen as a tic #tac toe board with x's and o's in appropriate positions.
The following Python program prints the board ['x', 'e', 'x', 'x', 'o', 'o', 'o', 'e', 'x']:
x='x'
o='o'
pipe = '|'
space = ' '
print(x,pipe,space,pipe,x)
print("---------")
print(x,pipe,o,pipe,o)
print("---------")
print(o,pipe,space,pipe,x)
This is what I know so far. I need to write the code for the aforementioned contract.
I have tried to fulfil the contract with this code:
def printFriendly(B):
board = [['x','x','o'],['','',''],['','x','o']]
#Output
print ("-------")
for row in board:
print ("|%s|") % ('|'.join(row))
print ("-------")
I continuously get error messages about incorrectly defining "board" as well as incorrect syntax. I have just started programming so I'm not sure what I'm doing wrong.
Any help is greatly appreciated.
Thanks,
Jordan