Click here to Skip to main content
13,739,612 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
test_board = ['1','2','3','4','5','6','7','8','9']
display_board(test_board)

def display_board(board):
print(" | | ")
print(" "+board[6]+" "'|'" "+board[7]+" "'|'" "+board[8]+" ")
print('------------')
print(" | | ")
print(" "+board[3]+" "'|'" "+board[4]+" "'|'" "+board[5]+" ")
print('------------')
print(" | | ")
print(" "+board[0]+" "'|'" "+board[1]+" "'|'" "+board[2]+" ")
end

What I have tried:

I am trying to pass a list as an argument to a function display_board.
Posted 12-Aug-18 4:50am
Updated 12-Aug-18 6:16am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I just tried your code and with a little modification it works fine. Remove the 'end' statement at the bottom of the file. You also need your function definition before the call to it. Something like (ensure proper indentation):
def display_board(board):
    print(" | | ")
    print(" "+board[6]+" "'|'" "+board[7]+" "'|'" "+board[8]+" ")
    print('------------')
    print(" | | ")
    print(" "+board[3]+" "'|'" "+board[4]+" "'|'" "+board[5]+" ")
    print('------------')
    print(" | | ")
    print(" "+board[0]+" "'|'" "+board[1]+" "'|'" "+board[2]+" ")

test_board = ['1','2','3','4','5','6','7','8','9']
display_board(test_board)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06-2016 | 2.8.180920.1 | Last Updated 12 Aug 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100