-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_tower_advanced.py
More file actions
49 lines (42 loc) · 1.22 KB
/
Copy pathbuild_tower_advanced.py
File metadata and controls
49 lines (42 loc) · 1.22 KB
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
def tower_builder(n_floors, block_size):
"""
Build Tower by the following given arguments:
number of floors (integer and always greater than 0)
block size (width, height) (integer pair and always greater than (0, 0))
Tower block unit is represented as *
Python: return a list;
JavaScript: returns an Array;
Have fun!
for example, a tower of 3 floors with block size = (2, 3) looks like below
[
[' ** '],
[' ** '],
[' ** '],
[' ****** '],
[' ****** '],
[' ****** '],
['**********'],
['**********'],
['**********']
]
and a tower of 6 floors with block size = (2, 1) looks like below
[
' ** ',
' ****** ',
' ********** ',
' ************** ',
' ****************** ',
'**********************'
]
"""
w, h = block_size
total = w
result = list()
block_width_per_floor = w
for _ in range(n_floors - 1):
total += 2 * w
for _ in range(n_floors):
for _ in range(h):
result.append(("*" * block_width_per_floor).center(total))
block_width_per_floor += w * 2
return result