Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to print proprely in python using for loops
    text
    copied!<p>I was wondering if I'm just trying to do something the wrong way or if I'm close to a viable solution.</p> <p>I have to print a chess board from a Dictionary given by the teacher.</p> <p>This is my code so far :</p> <pre><code>def printBoard(board): x = 0 for x in range(0,7): print("|-------------|-------------|-------------|-------------|-------------|-------------|-------------|-------------|") print("| | | | | | | | |") print("|",board[0,x],"|",board[1,x],"|",board[2,x],"|",board[3,x],"|",board[4,x],"|",board[5,x],"|",board[6,x],board[7,x]) print("| | | | | | | | |") print("|-------------|-------------|-------------|-------------|-------------|-------------|-------------|-------------|") board = { (0,0):"Rook[B]",(1,0):"Knight[B]",(2,0):"Bishop[B]", (3,0):"Queen[B]", (4,0):"King[B]", (5,0):"Bishop[B]", (6,0):"Knight[B]",(7,0):"Rook[B]", (0,1):"Pawn[B]",(1,1):"Pawn[B]", (2,1):"Pawn[B]",(3,1):"Pawn[B]", (4,1):"Pawn[B]",(5,1):"Pawn[B]",(6,1):"Pawn[B]", (7,1):"Pawn[B]", (0,2):"EMPTY", (1,2):"EMPTY", (2,2):"EMPTY", (3,2):"EMPTY", (4,2):"EMPTY", (5,2):"EMPTY", (6,2):"EMPTY", (7,2):"EMPTY", (0,3):"EMPTY", (1,3):"EMPTY", (2,3):"EMPTY", (3,3):"EMPTY", (4,3):"EMPTY", (5,3):"EMPTY", (6,3):"EMPTY", (7,3):"EMPTY", (0,4):"EMPTY", (1,4):"EMPTY", (2,4):"EMPTY", (3,4):"EMPTY", (4,4):"EMPTY", (5,4):"EMPTY", (6,4):"EMPTY", (7,4):"EMPTY", (0,5):"EMPTY", (1,5):"EMPTY", (2,5):"EMPTY", (3,5):"EMPTY", (4,5):"EMPTY", (5,5):"EMPTY", (6,5):"EMPTY", (7,5):"EMPTY", (0,6):"Pawn[N]",(1,6):"Pawn[N]", (2,6):"Pawn[N]",(3,6):"Pawn[N]", (4,6):"Pawn[N]",(5,6):"Pawn[N]",(6,6):"Pawn[N]", (7,6):"Pawn[N]", (0,7):"Rook[N]",(1,7):"Knight[N]",(2,7):"Bishop[N]", (3,7):"Queen[N]", (4,7):"King[N]", (5,7):"Bishop[N]", (6,7):"Knight[N]",(7,7):"Rook[N]", } printBoard(board) </code></pre> <p>My problem is that I cannot align my column.</p> <p>Maybe I should just send the dictionary into 8 different list and print them that way ?</p> <p>Thanks!</p> <p>Edit : </p> <p>Output : <img src="https://i.stack.imgur.com/lfihT.png" alt="Output"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload