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
好的,但请不要单独提问每一个小的变化。最好只问一次。 –