Think python(第二版)习题代码
3-2:
def do_twice(f, s1): f(s1) f(s1) def print_spam(s2): print(s2) def print_twice(s3): print(s3) print(s3) def do_four(f1,f2,s4): f1(f2,s4) f1(f2,s4) do_twice(print_twice, 'aaa') do_four(do_twice, print_spam, 'spam')
3-3.1:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def push1():
print('+ - - - -', end = ' ') # 默认情况下print会自动换行,可以在结尾打印一个空格改变这一行为
def push2():
print('| ', end = ' ')
def do_twice(f):
f()
f()
def do_four(f):
f()
f()
f()
f()
def row1():
do_twice(push1)
print('+')
def row2():
do_twice(push2)
print('|')
row1()
do_four(row2)
row1()
do_four(row2)
row1()

浙公网安备 33010602011771号