四行四列的小网格

先放效果图

Think Python 2 第三章练习题三我的解决办法。只能用学过的语句(还没讲到循环),for啊,while啊都不许用,于是我只能很蛮很直接了。如果要绘制两行两列的小网格,我只需把do_twice里的a、b函数从现在的重复4次变成重复两次即可。我觉得自己的脚本比官方提供的四行四列的小网格绘制法更易懂肿么破。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def plus():
    print('+ ', end='')
def minus():
    print('- ' * 4, end='')
def bar():
    print('| ', end='')
def space():
    print('  ' * 4, end='')
def do_twice(a,b):
    a()
    b()
    a()
    b()
    a()
    b()
    a()
    b()
def do_four():
    col()
    col()
    col()
    col()
def col():
    do_twice(bar,space)
    bar()
    print('')    
def row():
    do_twice(plus,minus)
    plus()
    print('') 
def print_grid():
    do_twice(row,do_four)
    row()
print_grid()

def plus(): print('+ ', end='') def minus(): print('- ' * 4, end='') def bar(): print('| ', end='') def space(): print(' ' * 4, end='') def do_twice(a,b): a() b() a() b() a() b() a() b() def do_four(): col() col() col() col() def col(): do_twice(bar,space) bar() print('') def row(): do_twice(plus,minus) plus() print('') def print_grid(): do_twice(row,do_four) row() print_grid()

本文链接:https://my.lmcjl.com/post/14119.html

展开阅读全文

4 评论

留下您的评论.