此代码创建了一个棋盘格,现在我必须在棋盘两侧从上到下包括数字8-> 1

时间:2014-02-05 00:56:19

标签: python 2d-games

def print_beams(num_columns):
    print("+-" * num_columns + "+")

def print_posts(num_columns):
    print("|#| " * num_columns + "| 8")

def print_box_row(num_columns):
    print_posts(num_columns)

def print_hash(num_columns):
    print("| |#" * num_columns + "|") 

def print_letters():
    print(" a", "b", "c", "d", "e", "f", "g", "h ")

def print_list():
    print("8")
    print(" ")
    print("7")
    print(" ")
    print("6")
    print(" ")
    print("5")
    print(" ")
    print("4")
    print("3")
    print(" ")
    print("2")
    print(" ")
    print("1")

def print_8_by_8():
        print_letters()
        print_beams(8)
        print_hash(4)

        print_beams(8)
        print_box_row(4)

        print_beams(8)
        print_hash(4)

        print_beams(8)
        print_box_row(4)

        print_beams(8)
        print_hash(4)

        print_beams(8)
        print_box_row(4)

        print_beams(8)
        print_hash(4)

        print_beams(8)
        print_box_row(4)

        print_beams(8)
        print_letters()

print_8_by_8()

1 个答案:

答案 0 :(得分:1)

也许是这样的?

row = '-'.join ('+' * 9)
row2 = '|'.join ('# ' * 6);
for i in range (8, 0, -1):
    print (' ', row)
    print (i, row2 [1 + (i % 2 * 2):] [:17] )
print (' ', row)
print ('  ', ' '.join ('abcdefgh') )

输出是:

  +-+-+-+-+-+-+-+-+
8 | |#| |#| |#| |#|
  +-+-+-+-+-+-+-+-+
7 |#| |#| |#| |#| |
  +-+-+-+-+-+-+-+-+
6 | |#| |#| |#| |#|
  +-+-+-+-+-+-+-+-+
5 |#| |#| |#| |#| |
  +-+-+-+-+-+-+-+-+
4 | |#| |#| |#| |#|
  +-+-+-+-+-+-+-+-+
3 |#| |#| |#| |#| |
  +-+-+-+-+-+-+-+-+
2 | |#| |#| |#| |#|
  +-+-+-+-+-+-+-+-+
1 |#| |#| |#| |#| |
  +-+-+-+-+-+-+-+-+
   a b c d e f g h