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)
我在试着做一个棋盘,但是左边的细胞一直在分开打印。也需要|之间的空格,但它必须紧挨着|。修正
新问题 现在我的输出每两行有一个空格,我已经更新了上面的代码。在
假设输出如下所示:
^{pr2}$我知道这个棋盘不是很方正,但这只是一个粗略的草稿。在
python3中的
print()
将打印新行,除非您告诉它不要这样做。传入end=''
以告诉它不要打印该换行符:相关问题 更多 >
编程相关推荐