0
s = [0,2,6,4,7,1,5,3]
def row_top():
print("|--|--|--|--|--|--|--|--|")
def cell_left():
print("| ", end = "")
def solution(s):
for i in range(8):
row(s[i])
def cell_data(isQ):
if isQ:
print("X", end = "")
return()
else:
print(" ", end = "")
def row_data(c):
for i in range(9):
cell_left()
cell_data(i == c)
def row(c):
row_top()
row_data(c)
print("\n")
solution(s)
我的輸出每兩行有一個空格,當不應該出現時,我不確定它在哪裏創建多餘的行。爲8皇后拼圖創建一個棋盤
輸出是假設是這樣的:
|--|--|--|--|--|--|--|--|
| | | | | | X| | |
|--|--|--|--|--|--|--|--|
| | | X| | | | | |
|--|--|--|--|--|--|--|--|
| | | | | X| | | |
|--|--|--|--|--|--|--|--|
| | | | | | | | X|
|--|--|--|--|--|--|--|--|
| X| | | | | | | |
|--|--|--|--|--|--|--|--|
| | | | X| | | | |
|--|--|--|--|--|--|--|--|
| | X| | | | | | |
|--|--|--|--|--|--|--|--|
| | | | | | | X| |
|--|--|--|--|--|--|--|--|
我知道這個棋盤不是很廣場但這只是目前初稿。
http://stackoverflow.com/questions/21654443/ascii-art-in-python-not-printing-in-one-line?一樣嗎? –
閱讀那一個的評論... – pakiboii
好的,但請不要單獨提問每一個小的變化。最好只問一次。 –