Skip to content

Commit 39a6fe6

Browse files
completes chapter 3
1 parent 585420f commit 39a6fe6

4 files changed

Lines changed: 56 additions & 2 deletions

File tree

‎ch3/ex3_1.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
# This is wrong on purpose to illustrate a point
44

‎ch3/ex3_2.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22

33
# This is wrong on purpose to illustrate a point
44

‎ch3/ex3_4.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
3+
def do_twice(f, value):
4+
f(value)
5+
f(value)
6+
7+
def print_twice(x):
8+
print x * 2
9+
10+
def do_four(f, value):
11+
do_twice(f, value)
12+
do_twice(f, value)
13+
14+
print("Reult of do_twice: ")
15+
do_twice(print_twice, 'spam')
16+
17+
print("Result of do_four: ")
18+
do_four(print_twice, 'spam')

‎ch3/ex3_5.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
3+
def print_boundary():
4+
print '+ '+'- ' * 4 + '+ ' + '- ' * 4 + '+'
5+
6+
def print_slash():
7+
print '/ '+' ' * 4 + '/ ' + ' ' * 4 + '/ '
8+
9+
def print_square():
10+
print_boundary()
11+
print_slash(), print_slash(), print_slash(), print_slash()
12+
print_boundary()
13+
print_slash(), print_slash(), print_slash(), print_slash()
14+
print_boundary()
15+
16+
def print_boundary_2():
17+
print '+ '+'- ' * 4 + '+ ' + '- ' * 4 + '+ ' +'- ' * 4 + '+ ' + '- ' * 4 + '+'
18+
19+
def print_slash_2():
20+
print '/ '+' ' * 4 + '/ ' + ' ' * 4 + '/ ' +' ' * 4 + '/ ' + ' ' * 4 + '/ '
21+
22+
def print_fourRows_fourColumns():
23+
print_boundary_2()
24+
print_slash_2(), print_slash_2(), print_slash_2(), print_slash_2()
25+
print_boundary_2()
26+
print_slash_2(), print_slash_2(), print_slash_2(), print_slash_2()
27+
print_boundary_2()
28+
print_slash_2(), print_slash_2(), print_slash_2(), print_slash_2()
29+
print_boundary_2()
30+
31+
if __name__ == "__main__":
32+
print_square()
33+
print " "
34+
print_fourRows_fourColumns()
35+
36+

0 commit comments

Comments
 (0)