Skip to content

Commit 5e1d772

Browse files
committed
exercises chapter 3
1 parent abdb369 commit 5e1d772

3 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def do_twice(f, a):
2+
f(a)
3+
f(a)
4+
5+
def print_spam():
6+
print('spam')
7+
8+
def print_twice(bruce):
9+
print(bruce)
10+
print(bruce)
11+
12+
if __name__ == "__main__":
13+
do_twice(print_twice, 'spam')

‎code/exercises/chapter-3/grid.py‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
def print_mais():
2+
print('+', end = ' ')
3+
4+
def print4traco():
5+
print('-'*4, end = ' ')
6+
7+
def print1pipe():
8+
print('|', end = ' ')
9+
10+
def print1espaco():
11+
print(' ', end = ' ')
12+
13+
def print4espaco():
14+
print(' '*4, end = ' ')
15+
16+
def linha_traco():
17+
print_mais()
18+
print4traco()
19+
20+
def linha_espaco():
21+
print1pipe()
22+
print4espaco()
23+
24+
def do_four(f):
25+
f()
26+
f()
27+
f()
28+
f()
29+
30+
def linha4brancopipe():
31+
do_four(linha_espaco)
32+
print1pipe()
33+
print('\n')
34+
35+
def draw_grid():
36+
do_four(linha_traco)
37+
print_mais()
38+
print('\n')
39+
do_four(linha4brancopipe)
40+
41+
if __name__ == '__main__':
42+
do_four(draw_grid)
43+
do_four(linha_traco)
44+
print_mais()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def right_justify(s):
2+
print(((70 - len(s))*' ')+s)
3+
4+
if __name__ == "__main__":
5+
print('right-justify\ninput a string: ')
6+
inps = input()
7+
right_justify(inps)

0 commit comments

Comments
 (0)