-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.3.py
87 lines (68 loc) · 2.1 KB
/
3.3.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'''
Exercise 3
Note: This exercise should be done using only the statements and other features we have learned so far.
Write a function that draws a grid like the following:
+ - - - - + - - - - +
| | |
| | |
| | |
| | |
+ - - - - + - - - - +
| | |
| | |
| | |
| | |
+ - - - - + - - - - +
Hint: to print more than one value on a line, you can print a comma-separated sequence of values:
print('+', '-')
By default, print advances to the next line, but you can override that behavior and put a space at the end, like this:
print('+', end=' ')
print('-')
The output of these statements is '+ -' on the same line. The output from the next print statement would begin on the next line.
Write a function that draws a similar grid with four rows and four columns.
'''
plus = '+'; bar = '-'; side = '|'; space = ' '
header = plus + (bar *4) + plus + (bar*4) + plus
sides = side + (space*4) + side + (space*4) + side
def two_by_four():
print(header + "\n"+((sides+"\n")*4) + header + "\n"+((sides+"\n")*4) + header)
def four_by_four():
top = '+----+----+----+----+' + '\n'; sides = '| | | | |' + '\n'
print(((top + sides*4)*2) + top + (sides*4 + top)+ (sides*4 + top))
'''
In [55]: two_by_four()
+----+----+
| | |
| | |
| | |
| | |
+----+----+
| | |
| | |
| | |
| | |
+----+----+
In [56]: four_by_four()
+----+----+----+----+
| | | | |
| | | | |
| | | | |
| | | | |
+----+----+----+----+
| | | | |
| | | | |
| | | | |
| | | | |
+----+----+----+----+
| | | | |
| | | | |
| | | | |
| | | | |
+----+----+----+----+
| | | | |
| | | | |
| | | | |
| | | | |
+----+----+----+----+
In [57]:
'''